请帮我在GSP页面显示中定义。
如果我没有固定在一定时间,我有3或8或15或17 我有像这样的结构 如果FOR 5套
<LI>
<DIV class= A>
<DIV class=B>
<DIV class=row>
<DIV class=col>1</DIV>
<DIV class=col>2</DIV>
<DIV class=col>3</DIV>
<DIV class=col>4</DIV>
</DIV>
<DIV class=row>
<DIV class=col>5</DIV>
</DIV>
</DIV>
</DIV>
</LI>
如果它设置了15,那么
<LI>
<DIV class= A>
<DIV class=B>
<DIV class=row>
<DIV class=col>1</DIV>
<DIV class=col>2</DIV>
<DIV class=col>3</DIV>
<DIV class=col>4</DIV>
</DIV>
<DIV class=row>
<DIV class=col>5</DIV>
<DIV class=col>6</DIV>
<DIV class=col>7</DIV>
<DIV class=col>8</DIV>
</DIV>
</DIV>
</DIV>
</LI>
<LI>
<DIV class= A>
<DIV class=B>
<DIV class=row>
<DIV class=col>9</DIV>
<DIV class=col>10</DIV>
<DIV class=col>11</DIV>
<DIV class=col>12</DIV>
</DIV>
<DIV class=row>
<DIV class=col>13</DIV>
<DIV class=col>14</DIV>
<DIV class=col>15</DIV>
</DIV>
</DIV>
</DIV>
</LI>
我想做的是
<g:set var="dataSetTotal" value="${15 }" />
<g:set var="setDataRange" value="${8 }" />
<g:set var="liDivCount" value="${(int)((dataSetTotal/setDataRange)+1)}" />
${setDataRange}
${liDivCount }
<g:each in="${1..liDivCount}">
${it} //Run which need li section
<g:each in="${1..setDataRange}" var="inside" status="j">
print ${j }
<g:if test="${j % 4 ==0 }">
print row
</g:if>
</g:each>
</g:each>
答案 0 :(得分:0)
Groovy在Lists上添加了一个方便的collate()方法,可以按如下方式使用:
<g:set var="itemsPerLi" value="${8}" />
<g:set var="itemsPerRow" value="${4}" />
<g:set var="myList" value="${[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]}" />
<g:each in="${myList.collate(itemsPerLi)}" var="a">
<LI>
<DIV class="A">
<DIV class="B">
<g:each in="${a.collate(itemsPerRow)}" var="row">
<DIV class="row">
<g:each in="${row}"><DIV class="col">${it}</div></g:each>
</DIV>
</g:each>
</DIV>
</DIV>
</LI>
</g:each>