流星火焰通过数组索引选择一个特定的项目 [英] Meteor blaze select a specific item by the array index
本文介绍了流星火焰通过数组索引选择一个特定的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在流星火焰中访问每个块助手中的数组索引?
Is there a way to access array index inside each block helper in meteor blaze?
我正在寻找类似的东西.
I am looking for something like this.
{{#each myarray}}
{{this.arrayIndex3}}
{{/each}}
推荐答案
恐怕还没有一种标准的方法,但是您可以编写一个将数组映射到索引/值对列表的助手.并对其进行迭代以显示您想要的内容.
I'm afraid there is not yet a standard way to do this, however you can write a helper that maps your array to a list of index / value pairs and iterate over it to display what you want.
JS
Template.myTemplate.helpers({
myArrayWithIndex: function(){
return _.map(this.myArray,function(value,index){
return {
index:index,
value:value
};
});
}
});
HTML
<template name="myTemplate">
{{#each myArrayWithIndex}}
myArray[{{index}}] == {{value}}
{{/each}}
</template>
您还可以定义自己的名为{{#eachWithIndex}}
的块帮助程序,以自动执行此过程.
You could also define your own block helper called {{#eachWithIndex}}
that would automate this process.
这篇关于流星火焰通过数组索引选择一个特定的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文