gpt4 book ai didi

java - Play2 - 模板 -> 递增

转载 作者:搜寻专家 更新时间:2023-11-01 01:00:50 24 4
gpt4 key购买 nike

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

伪代码:

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


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

最佳答案

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

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

方法 zipWithIndex 创建元组列表。

关于java - Play2 - 模板 -> 递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12251504/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com