2013-07-31 32 views
0

多个索引元件我有构成这样的车把模板:options.data在车把辅助

{{#each array}} 
    some stuff 
    {{#each array2}} 
     some more stuff 
     {{#customHelper}}{{/customHelper}} 
    {{/each}} 
{{/each}} 

每个阵列包含四个项目。

车把助手看起来是这样的:

Handlebars.registerHelper('customHelper', function(options){ 
    console.log(options.data); 
}); 

options.data包含倍(index)它已经通过#each数量。如果有多个#each,它将返回最里面的一个。但是,我想要最外面的#each的索引。

记录options.data给出:

Object {index: 0, index: 0} 
Object {index: 1, index: 0} 
Object {index: 2, index: 0} 
Object {index: 3, index: 0} 
Object {index: 0, index: 1} 
Object {index: 1, index: 1} 
Object {index: 2, index: 1} 
Object {index: 3, index: 1} 
Object {index: 0, index: 2} 
Object {index: 1, index: 2} 
Object {index: 2, index: 2} 
Object {index: 3, index: 2} 
Object {index: 0, index: 3} 
Object {index: 1, index: 3} 
Object {index: 2, index: 3} 
Object {index: 3, index: 3} 

这表明,两个指数都在那里。第一个索引是最里面的#each,第二个索引是最外面的索引。据我所知,在javascript对象中不应该有两个相同的键。

日志记录options.data.index给出第一个index,而不是第二个。

是否可以访问第二个index,如果是这样,怎么办?

回答

0

我想通了。 删除索引:

delete options.data.index; 

将只删除了第一个,所以现在

options.data.index 

将返回的外#each

指数