我是靠谱客的博主 紧张大地,这篇文章主要介绍freemarker List 遍历换行,现在分享给大家,希望可以做个参考。

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

需求:将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内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(162)

评论列表共有 0 条评论

立即
投稿
返回
顶部