我想在播放模板中改进算法:
linklist.scala.html
<div class="row">
<div class="span6">
<table class="table table-hover">
@for((l,i) <- linkList.zipWithIndex) {
@if((i/2)*2==i) {
@* even index *@
@components.link(l)
}
}
</table>
</div>
<div class="span6">
<table class="table table-hover">
@for((l,i) <- linkList.zipWithIndex) {
@if((i/2)*2!=i) {
@* ood index *@
@components.link(l)
}
}
</table>
</div>
</div>
link.scala.html
@(link: Link)
<tr>
<td><a href="@link.uri.toString()" class="btn btn-primary">@link.uri.getHost()@link.uri.getPath()</a> </td>
<td>@link.description</td>
</tr>
我想在linklist.scala.html中只有一个<div class="span6">
。唯一的区别是if语句,我将链表分为两部分(奇数和偶数索引号)。欢迎任何建议。谢谢!
答案 0 :(得分:2)
不确定确切的语法,但我认为这种方法可以为您提供所需的标记:
<div class="row">
@for(remainder <- List(0,1)) {
<div class="span6">
<table class="table table-hover">
@for((l,i) <- linkList.zipWithIndex) {
@if(i%2 == remainder) {
@components.link(l)
}
}
</table>
</div>
}
</div>