【发布时间】:2016-05-07 12:03:27
【问题描述】:
我正在使用来自 Meteor 的 Blaze 作为 html 模板,并且我有多个循环,例如:
let objects = [{name: 'John', age: 18}, {name: 'Foo', age: 25}, {name: 'Bar', age: 35}]
let attrs = ['name', 'age']
{{#each objects}}
<h3>Object {{@index}}</h3>
{{#each attrs}}
[...] // code here
{{/each}}
{{/each}}
我知道:
-
{{@index}}用于了解当前循环索引(因此[..]{{@index}}是 attrs 数组上索引的引用 -
{{this}}用于知道当前循环值(如[...]{{value}}是name或age) -
{{..}}是对父循环值的引用(因此[...]{{..}}是当前对象,在第一个循环中)
现在,我想在[...] 上为objects 循环当前的索引。我在 Google 和 Stackoverflow 上搜索了很多,但没有找到。
【问题讨论】:
标签: javascript meteor each meteor-blaze