Play2 - Template -> incrementing

2019-04-10 02:51发布

How do I declare and increment a variable in play2? (in .scala.html templates)

Pseudo code:

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


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

2条回答
你好瞎i
2楼-- · 2019-04-10 03:02

to declare at template

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

for increment in template

@(i+=1)
查看更多
SAY GOODBYE
3楼-- · 2019-04-10 03:20

Do you really need counter and incrementing? You can do this:

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

Method zipWithIndex creates list of tuples.

查看更多
登录 后发表回答