如何在嵌套循环中访问外部{{#each}}集合值

hyd*_*yde 11 meteor

在循环中访问外部#each集合值的标准方法是什么?例如:

<template name="example">
  {{#each outerCollection}}
  <tr>
    {{#each innerCollection}}
      <td>{{aaa}}</td>
    {{/each}}
  </tr>
  {{/each}}
</template>

Template.example.aaa = function(){
  // cannot access outerCollection values
}
Run Code Online (Sandbox Code Playgroud)

在上面的Template.example.aaa中,this指向内部集合.

我找不到访问outerCollection项的方法.我的解决方案如下,我正在定义自己的帮助函数.它是实现此目的的标准Meteor方式吗?

<template name="example">
  {{#each outerCollection}}
  <tr>
    {{#each innerCollection}}
      <td>{{myHelper ../outerItem innerItem}}</td>
    {{/each}}
  </tr>
  {{/each}}
</template>

Handlebars.registerHelper('myHelper', function (outItem, inItem) {
  // can access outerCollection via outerItem
});
Run Code Online (Sandbox Code Playgroud)

我发现内部事件处理程序访问的类似问题.

Dav*_*ser 12

我想你自己已经回答了这个问题!使用../记录在https://github.com/meteor/meteor/wiki/Handlebars中.