【问题标题】:Freemarker - Evaluating an expression one after anotherFreemarker - 一个接一个地评估一个表达式
【发布时间】:2015-03-31 10:00:54
【问题描述】:

这里的问题是我将 indexc 作为评估表达式,在评估 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]

你们中有人知道这个问题的任何解决方法吗?

提前致谢!

【问题讨论】:

    标签: freemarker


    【解决方案1】:

    在这种情况下,评估从左到右进行,就像它是 (c.index)[1]。这在几乎所有其他语言中也是如此。如果我理解得很好,index[1] 将评估为字符串"firstname",并且您希望c.firstname 生效。那么,语法就是c[index[1]]

    【讨论】:

    • 这就像一个魅力!谢谢你拯救了我的一天:)
    猜你喜欢
    • 2013-12-22
    • 1970-01-01
    • 2019-08-20
    • 2016-09-27
    • 2021-07-18
    • 1970-01-01
    • 2020-09-06
    • 2020-10-22
    • 1970-01-01
    相关资源
    最近更新 更多