如何在Play的模板中获取迭代器的索引? [英] How to get iterator's index in Play's template?
本文介绍了如何在Play的模板中获取迭代器的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在循环中使用一个计数器,因此每个表的行都有其唯一的id
属性,该属性指示当前循环迭代.如何访问当前索引? (在标记为ITERATOR_HERE
的示例代码中)
I want to use a counter in a loop, so each table's row has its unique id
attribute which indicates the current loop iteration. How can I access the current index? (in sample code marked as ITERATOR_HERE
)
<table id="table_id" class="display">
<thead>
<th>Key</th>
<th>Value</th>
<th></th>
</thead>
<tbody>
#{list items:paras, as:'elem' }
<tr>
<td id="ITERATOR_HERE">${elem.sendAllKey}</td>
<td>${elem.sendAllValue}</td>
<td>button</td>
</tr>
#{/list}
</tbody>
</table>
推荐答案
list标记创建一个包含当前迭代编号的变量varname_index
.有关更多信息,请参见标签参考;)
The list tag creates a variable varname_index
containing the current iteration number. See the tag reference for more information ;)
因此,您的代码段变为:
So, you snippet becomes:
#{list items:paras, as:'elem' }
<tr>
<td id="ITERATOR_${elem_index}">${elem.sendAllKey}</td>
<td>${elem.sendAllValue}</td>
<td>button</td>
</tr>
#{/list}
这篇关于如何在Play的模板中获取迭代器的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文