用freemarker标签实现一行五列的表格算法
发布时间:2010/6/7 11:08:45 来源:城市学习网 编辑:ziteng
1 <table cellspacing="0" cellpadding="0" border="0" class="listTable">
2 <#list tagPage.result as tag>
3 <#-- 取5的模,即除于5的倍数余数为0的生成行的开头<tr> -->
4 <#if tag_index%5==0><tr></#if>
5 <td>
6 <a href="post_bytag.action?tagId=${tag.id}">${tag.name}</a>(${tag.counts})
7 </td>
8 <#-- 如果最后一个不是刚好5列,则要补充完剩下的列 -->
9 <#if tag_index == (tagPage.result?size-1) && tag_index%5!=4>
10 <#assign end=(tagPage.result?size-tag_index+1) />
11 <#-- 根据缺少的列数重新定义一个list生成列 -->
12 <#list 0..end as x>
13 <td> </td>
14 </#list>
15 </tr>
16 </#if>
17 <#-- 取5的模,即除于5的倍数余数为4(0到4刚好5列)的生成行的结尾</tr> -->
18 <#if tag_index%5==4></tr></#if>
19 </#list>
20 </table>