在meteor中有一种方法可以访问空格键中的数组索引 [英] In meteor is there a way to access array index in spacebars
本文介绍了在meteor中有一种方法可以访问空格键中的数组索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用meteor Shark分支。
I am using meteor Shark branch.
有没有办法在空格键中的每个块助手中访问数组索引?
Is there a way to access array index inside each block helper in spacebars?
我正在寻找类似的东西。
I am looking for something like this.
{{#each humans}}
{{this.arrayIndex}}
{{/each}}
推荐答案
meteor> = 1.2
Spacebars在1.2中获得了很多功能,包括原生 @index
。不再需要助手来解决这个问题 - 您只需执行此操作:
meteor >= 1.2
Spacebars gained a lot of functionality in 1.2, including a native @index
. Helpers are no longer needed to solve this problem - you can simply do this:
<template name="showHumans">
<ul>
{{#each humans}}
<li>{{@index}}: {{name}}</li>
{{/each}}
</ul>
</template>
meteor< 1.2
我在流星书中看到了一个使用模板助手的类似示例动画章节。您可以将 map
应用于人体光标,以便添加如下索引:
meteor < 1.2
I saw a similar example using template helpers in the meteor book in the "animations" chapter. You can apply a map
to the humans cursor in order to add an index like so:
Template.showHumans.helpers({
humans: function() {
return Humans.find({}, {sort: {hotness: -1}}).map(function(human, index) {
human.rank = index;
return human;
});
}
});
<template name="showHumans">
<ul>
{{#each humans}}
<li>{{rank}}: {{name}}</li>
{{/each}}
</ul>
</template>
这篇关于在meteor中有一种方法可以访问空格键中的数组索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文