javascript – 在Meteor.js模板中打印循环索引

栏目: Node.js · 发布时间: 5年前

内容简介:翻译自:https://stackoverflow.com/questions/22142432/print-the-loop-index-in-meteor-js-templates

参见英文答案 > How can I get the index of an array in a Meteor template each loop? 6个

我在meteorjs中有一个对象列表,我在meteorjs模板中迭代

{{#each objects}}
{{/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;
    }

    return objects;
}

然后做:

{{#each object_with_index}}
    <p>This is number {{index}}</p>
{{/each}}

不是最漂亮的方式,但其他变化基本上会在引擎盖下做同样的事情(例如,如果你使用地图)

翻译自:https://stackoverflow.com/questions/22142432/print-the-loop-index-in-meteor-js-templates


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Computational Geometry

Computational Geometry

Mark de Berg、Otfried Cheong、Marc van Kreveld、Mark Overmars / Springer / 2008-4-16 / USD 49.95

This well-accepted introduction to computational geometry is a textbook for high-level undergraduate and low-level graduate courses. The focus is on algorithms and hence the book is well suited for st......一起来看看 《Computational Geometry》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具