我正在尝试迭代一个playframework视图,但现在没有成功。我有以下结构:
@if(list != null) {
for(a <- 0 to list.size()/5)
{
// some html, where I want to get the value of a
for(b <- a*5 to a*5+5) // here I want to use the a value again
{
some html
}
}
所以我的问题是如何获取循环的当前索引以便我能够使用它。
答案 0 :(得分:5)
你应该把它组合成一个for循环:
@if(list != null) {
@for{a <- 0 to list.size()/5
b <- a*5 to a*5+5}
yield html
}
}
并使用选项代替null
检查。
您还可以使用map
函数转换列表。请参阅Play文档中的详细信息 - http://www.playframework.com/documentation/2.0/ScalaTemplates