【问题标题】:Error in accessing parent scope property in handlebars访问车把中的父范围属性时出错
【发布时间】:2015-08-15 19:52:08
【问题描述】:

我正在使用带有嵌套 each 和 if 助手的把手模板。看起来是这样的

{{each resultSet}}
   ...some html...
   {{each segment}}
       {{if @index}}
            ---some html--
            {{../someParentValue}}
       {{/if}}
   {{/each}}
{{/each}}

当我访问此someParentValue 时,我在控制台"Uncaught TypeError: Cannot read property '1' of undefined" 中收到此错误

如果我在路径中添加另一个级别,即 ../../someParentValue 以进入每个结果集的范围,则会收到错误 "Uncaught TypeError: Cannot read property '2' of undefined"

我不确定这可能有什么问题,因为在检查结果集时,我可以看到该结果集中的每个项目都有我要访问的属性。

【问题讨论】:

    标签: javascript handlebars.js templating handlebarshelper


    【解决方案1】:

    Handlebars 3.0 中的新功能,可以从支持助手接收命名参数。

    {{each resultSet as |rs}}
       ...some html...
       {{each segment as |seg}}
           {{if @index}}
                ---some html--
                {{rs.someResultSetProperty}}
           {{/if}}
       {{/each}}
    {{/each}}
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-23
      • 2016-09-04
      • 2020-09-27
      • 1970-01-01
      • 2016-08-27
      • 2019-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多