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
,如果是這樣,怎麼辦?