Freemarker:按索引从数组中获取元素

时间:2016-08-11 13:31:04

标签: freemarker

我有这段代码:

<#local slots = time_utils.get_slots(objectArray) />
<#local days = time_utils.get_short_days(objectArray) />
<#local index = 0 />
<#list days as day>
    <#list slots as slot>
        <#if time_utils.is_slot_available(objectArray[index], slot, day)> bla bla </#if>
        <#local index = index + 1 />
    </#list>
</#list>

功能:

<#function is_slot_available date slot short_date>
    <#local hour_of_date = '${date.startsAt?string["HH"]}' />    
    <#local day_of_date = '${date.startsAt?string["dd"]}' /> 
    <#if (hour_of_date == '${slot[6..7]}') && (day_of_date == '${short_date[short_date?length-5..short_date?length-4]}')>
        <#return true />    
    </#if>
    <#return false />
</#function>

当我运行此代码时,我有错误: 执行宏时出错:is_slot_available 必需参数:未指定日期。

当我将index替换为0或函数调用中objectArray[index]中的任何数字时,我都不会收到此错误。

那么这样做的严格方法是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

感谢@ddekany:

  

我猜索引的值会增加,直到超出范围,或者   遇到存储null的数组项。


这就是问题所在。

相关问题