在循环中访问外部#each集合值的标准方法是什么? 例如:
<template name="example">
{{#each outerCollection}}
<tr>
{{#each innerCollection}}
<td>{{aaa}}</td>
{{/each}}
</tr>
{{/each}}
</template>
Template.example.aaa = function(){
// cannot access outerCollection values
}
在上面的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
});
我发现了一个 类似的问题 对于内部事件处理程序访问的情况。