4

如何在 play2 中声明和增加变量?(在.scala.html 模板中)

伪代码:

@counter
@for(l <- list){
<span class="data-@counter">


</span>
@(counter += 1)
}
4

2 回答 2

18

你真的需要计数器和递增吗?你可以这样做:

@for((l, index) <- list.zipWithIndex){
    <span class="data-@index">@l</span>     
}

方法zipWithIndex创建元组列表。

于 2012-09-03T17:32:42.263 回答
5

在模板中声明

@import java.math.BigInteger; var i=1

用于模板中的增量

@(i+=1)
于 2014-02-19T12:06:11.447 回答