0
获得从数组元素我有这样的代码: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 必需参数:未指定日期。
当我objectArray[index]
在函数调用替换index
由0或任意数量我没有得到这个错误。
那么什么是rignt办法做到这一点?
谢谢!
你有没有注意到,当你调用函数,你传递'day'为'slot'和'slot'为'short_date'? –
不,我没有。谢谢! – dardy
我想的'index'的值增加,直到它超出了范围,或运行到存储'null'一个数组项。 (无关你的问题,但请注意,这是可能的:'<#local自指数++ />') – ddekany