Generating a loop counter in Ember.js #each

泪湿孤枕 提交于 2019-12-02 00:20:47

I'd recommend writing a handlebars helper, in which you can execute arbitrary javascript. See http://handlebarsjs.com for some examples.

Alternatively, you could include the positional IDs on your child views (not your models).

With handlebars.js (v. 1.0.rc1) I could do this:

 {{#each links}}
   <li>{{@index}} - {{url}}</li>
 {{/each}}

Turns out providing a loop counter is the exact subject of the final example on this page:

http://handlebarsjs.com/block_helpers.html

(Dan G already pointed out the "writing a helper" solution in his answer, but since there's already a published example, I wanted to create a fresh answer to make the link more prominent.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!