Meteor 1.2将@Index传递给子模板

reu*_*b87 5 meteor spacebars meteor-blaze

刚刚开始使用Meteor,所以我可能会遗漏一些基本的东西.在Meteor 1.2中,他们有{{@index}}指令.

在模板中,如果我有:

...
{{#each items}}
    {{@index}}
    {{> childTemplate}} 
{{/each}}
...
<template name="childTemplate">
{{@index}}
</template>
Run Code Online (Sandbox Code Playgroud)

@index主模板将工作,但一个在childTemplate不会.我使用它的工作是调用childTemplate传入@index:

{{> childTemplate @index=@index}} 
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?还是有更多的东西?

Kei*_*las 4

是的,没关系

我在这里回答了一个类似的问题:-

如何获取流星中嵌套#each的@index

但在这种情况下传递它是好的。

Meteor必须"../var"到达父上下文,但那是模板上下文,而不是each块,所以我认为没有更多的meteor方式