Play2-模板->递增 [英] Play2 - Template -> incrementing

查看:44
本文介绍了Play2-模板->递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

伪代码:

@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>     
}

方法zipWithIndex创建元组列表.

这篇关于Play2-模板-&gt;递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆