Freemarker - 一个接一个地评估一个表达式
Freemarker - Evaluating an expression one after another
这里的问题是我有 index 和 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]
你们中有人知道解决此问题的方法吗?
提前致谢!
在这种情况下,评估是从左到右进行的,就像 (c.index)[1]
一样。几乎所有其他语言也是如此。如果我理解得很好,index[1]
将评估为字符串 "firstname"
,并且您希望 c.firstname
生效。然后,语法是 c[index[1]]
.
这里的问题是我有 index 和 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]
你们中有人知道解决此问题的方法吗?
提前致谢!
在这种情况下,评估是从左到右进行的,就像 (c.index)[1]
一样。几乎所有其他语言也是如此。如果我理解得很好,index[1]
将评估为字符串 "firstname"
,并且您希望 c.firstname
生效。然后,语法是 c[index[1]]
.