2016-01-12 61 views
5

刚开始使用流星,所以我可能会缺少一些基本的东西。在Meteor 1.2中,他们有{{@index}}指令。流星1.2通过@Index儿童模板

在,如果我有一个模板:

... 
{{#each items}} 
    {{@index}} 
    {{> childTemplate}} 
{{/each}} 
... 
<template name="childTemplate"> 
{{@index}} 
</template> 

主模板的@index会工作,但一个在childTemplate不会。我周围的工作已经完成使用它是调用childTemplate传递@index

{{> childTemplate @[email protected]}} 

这是做了正确的方法是什么?还是有更多的记忆?

回答

4

是的,这很好

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

How to get the @index of nested #each in meteor

但在这种情况下,通过它的好。

流星有"../var"才能到父上下文,但该模板背景下,不是每个块,所以我不认为还有一个更meteory方式

+0

谢谢,我只是要它映射到一个不同的变量,甚至没有'@'的索引,但是调用它'@ index'看起来很灵活。我仍然有点不确定为什么孩子模板不能访问这个'@ index',可能应该问这个问题。 – reubenb87