简体   繁体   English

Play2 - 模板 - >递增

[英]Play2 - Template -> incrementing

How do I declare and increment a variable in play2? 如何在play2中声明和增加变量? (in . scala.html templates ) (在.scala.html模板中

Pseudo code: 伪代码:

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


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

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. 方法zipWithIndex创建元组列表。

to declare at template 在模板上声明

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

for increment in template 用于模板中的增量

@(i+=1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM