在Meteor.js模板中打印循环索引 [英] Print the loop index in Meteor.js templates
本文介绍了在Meteor.js模板中打印循环索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
{{#each objects}}我有一个meteorjs中的对象列表,我正在迭代meteorjs模板。
{{/ each}}
在模板中,我要打印循环迭代。也就是说,如果对象列表的长度是100,我想在模板中打印1到100之间的数字。我怎么做到这一点?
解决方案
现在你不能在你的助手
Template.yourtemplatename.object_with_index = function(){
var objects = Template.yourtemplatename.objects();
for(var i = 0; i = objects.length; i ++){
objects [i] .index = i;
}
返回对象;
}
然后执行:
{{#each object_with_index}}
< p>这是数字{{index}}< / p>
{{/ each}}
不是最漂亮的方式,但其他变体基本上会做(例如,如果您使用 map
)
I have a list of objects in meteorjs which I am iterating in meteorjs templates like
{{#each objects}}
{{/each}}
In the template I want to print the number of the loop iteration. That is, if the length of the objects list is 100 I want to print the numbers from 1 to 100 in the template. How can I do this?
解决方案
You can't do this at the moment without giving in an index in your helper, i.e
Template.yourtemplatename.object_with_index = function() {
var objects = Template.yourtemplatename.objects();
for(var i = 0; i=objects.length; i++) {
objects[i].index = i;
}
return objects;
}
Then do:
{{#each object_with_index}}
<p>This is number {{index}}</p>
{{/each}}
Not the prettiest way, but other variations would basically do the same thing under the hood (e.g if you used a map
)
这篇关于在Meteor.js模板中打印循环索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文