2019独角兽企业重金招聘Python工程师标准>>> 
需求:将list中的值遍历为两列,且当list个数为奇数时添加一个空行列
<#list (orders.attributeItems["xx"])?split(",") as item>
<#if (item_index+1) % 2 == 0>
<td><button>${(item_index+1)}档:${(item)!''}元
${((orders.attributeItems["xx"])?split(","))?size}</button></td>
</tr>
<#elseif (((orders.attributeItems["xx"])?split(","))?size % 2 == 1 )
&& ((item_index+1) % ((orders.attributeItems["xx"])?split(","))?size ==0)>
<tr>
<td><button>${(item_index+1)}档:${(item)!''}元</button></td>
<td> </td>
</tr>
<#else>
<tr>
<td><button>${(item_index+1)}档:${(item)!''}元</button></td>
</#if>
</#list>
Ps:
(orders.attributeItems["xx"])?split(","):将字符串划分为list集合。
((orders.attributeItems["xx"])?split(","))?size % 2 == 1 :通过集合长度判断是否为奇数列
item_index+1:集合下标(从1开始)
转载于:https://my.oschina.net/u/3530220/blog/1559689
最后
以上就是紧张大地最近收集整理的关于freemarker List 遍历换行的全部内容,更多相关freemarker内容请搜索靠谱客的其他文章。
发表评论 取消回复