freemarker处理list的内置函数
- first 没有括号
- last 没有括号
- seq_contains
- seq_index_of
- size 没有括号
- reverse
- sort
- sort_by 如果list中放置的是对象的话,可以根据某个属性来排序
- chunk 将list分块
<#assign listVar = [1,2,3,4,5,6,7,8,9,0,1,2]/>
<#list listVar?chunk(4)?last as item>
${item}
</#list>
//chunk(4)的意思是,从列表中顺序的一次取4个元素,取出来组成一个列表
//上面的例子
//第一个列表是:[1,2,3,4] 4个元素
//第二个列表是:[5,6,7,8] 4个元素
//第三个列表是:[9,0,1,2] 4个元素
//新列表:[[1,2,3,4],[5,6,7,8],[9,0,1,2]]
例如
[#list paymentPlugins?chunk(5, "") as row] <tr> [#list row as paymentPlugin] [#if paymentPlugin?has_content] [#if paymentPlugin.id == 'weixinNativePaymentPlugin'] <td> <input type="radio" id="${paymentPlugin.id}" name="paymentPluginId" value="${paymentPlugin.id}"[#if paymentPlugin == defaultPaymentPlugin] checked="checked"[/#if] /> <label for="${paymentPlugin.id}"> [#if paymentPlugin.logo?has_content] <em title="${paymentPlugin.paymentName}" style="background-image: url(${paymentPlugin.logo});"> </em> [#else] <em>${paymentPlugin.paymentName}</em> [/#if] </label> </td> [#elseif paymentPlugin.id == 'alipayDirectPaymentPlugin'] <td> <input type="radio" id="${paymentPlugin.id}" name="paymentPluginId" value="${paymentPlugin.id}"[#if paymentPlugin == defaultPaymentPlugin] checked="checked"[/#if] /> <label for="${paymentPlugin.id}"> [#if paymentPlugin.logo?has_content] <em title="${paymentPlugin.paymentName}" style="background-image: url(${paymentPlugin.logo});"> </em> [#else] <em>${paymentPlugin.paymentName}</em> [/#if] </label> </td> [/#if] [#else] <td> </td> [/#if] [/#list] </tr> [/#list]
标签:内置,freemarker,chunk,list,paymentPlugin,列表,content,nbsp From: https://www.cnblogs.com/webSnow/p/17295132.html