Freemarker - 一个接一个地评估一个表达式

时间:2015-02-01 09:03:09

标签: freemarker

这里的问题是我有索引 c 作为评估表达式,在评估 index [1] 之后,它会作为 userDetails 的参数。因此,例如喜欢 c.firstname

   <#ftl encoding='UTF-8'>
   <#list param?chunk(3) as index>
       <#list userDetails as c>
           ${c.index[1]}
       </#list>
   </#list>

但是,我假设Freemarker一次评估所有表达式,因此当运行这段代码时, index [1] 尚未评估。因此,我收到了这个错误。

FreeMarker template error:
The following has evaluated to null or missing:
==> c.index  [in template "src/template_fixedlength.ftl" at line 5, column 19]

您是否有人知道此问题的解决方法?

提前致谢!

1 个答案:

答案 0 :(得分:0)

在这种情况下评估从左到右发生,就像是(c.index)[1]一样。几乎所有其他语言都是如此。如果我理解得很好,index[1]会评估字符串"firstname",并且您希望c.firstname生效。然后,语法为c[index[1]]