我正在使用 jQuery 模板插件,不知道如何获取项目的索引:http://api.jquery.com/category/plugins/templates/ http://api.jquery.com/category/plugins/templates/
这是我的代码:
<script id="optionTmpl" type="text/x-jquery-tmpl">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
{{each Answers}}
<tr>
<th><input type="radio" name="group1" value="${this.AnswerID}" /></th>
<td>${this.AnswerText}</td><!-- add number in this line--->
</tr>
{{/each}}
</table>
</script>
我想以如下格式显示答案
1)回答1, 2)回答2, 3)回答3
or
a) 答案 1, b) 答案 2, c) 答案 3
我应该怎么办?
有一个隐含的$index
(and $value
)内可用{{each}} loop http://api.jquery.com/template-tag-each/,您可以在这里使用它:
<script id="optionTmpl" type="text/x-jquery-tmpl">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
{{each Answers}}
<tr>
<th><input type="radio" name="group1" value="${this.AnswerID}" /></th>
<td>${this.AnswerText} ${$index + 1}</td>
</tr>
{{/each}}
</table>
</script>
您可能想要添加1
因为它是0
基于,就像我上面所说的那样。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)