【问题标题】:How do I access a meteor parent template data context inside #each?如何访问#each 中的流星父模板数据上下文?
【发布时间】:2015-05-24 00:29:59
【问题描述】:

当我在#each 循环中时,有没有办法访问父模板的助手?

<template name="template2">
  {{test}}<br/>
  {{#each list}}
    {{this}}:{{../test}}<br/>
  {{/each}}
</template>

第一个 {{test}} 有效,循环中的那个无效。如果这是答案,我也尝试过 {{../this.test}} 失败。

.. 语法在这里不起作用吗?我找到了this 的答案,这似乎表明确实如此,但正如您在此meteorpad 中看到的那样,它没有。

【问题讨论】:

    标签: meteor


    【解决方案1】:

    问题的标题表示父子关系,但在示例中只有一个模板。帮助器可用于整个模板,因此在这种情况下上下文无关紧要。只需像这样使用{{test}}

    <template name="template2">
      here:{{test}}<br/>
      {{#each list}}
        {{this}}:{{test}}<br/>
      {{/each}}
    </template>
    

    【讨论】:

    • 啊……太简单了。我假设助手遵循数据上下文。谢谢!
    猜你喜欢
    • 2015-05-06
    • 2014-02-23
    • 2016-04-22
    • 2014-12-30
    • 2018-01-03
    • 1970-01-01
    • 2017-02-01
    • 2015-06-11
    • 2017-02-09
    相关资源
    最近更新 更多