jTemplates中的局部变量/ for循环

时间:2012-04-23 17:25:32

标签: jquery jtemplates

是否可以在jtemplate中创建局部变量或for循环(而不是foreach)?我想给HTML元素提供唯一的id,并需要一个计数器或其他东西。谢谢!

1 个答案:

答案 0 :(得分:4)

使用$index

$index - index of the element in the table
$iteration - ID of the iteration (the next number begins from 0)
$first - is this the first iteration?
$last - is this the last iteration?
$total - the total number of iterations

{#foreach $T.Rows as row}
  $T.row$index
{#/for}

阅读http://www.codeproject.com/Articles/45759/jQuery-jTemplates-Grid