How can I get the index number of the {{#each}} list in Meteor? It seems like it should be really simple, but I can't find it.
Asked
Active
Viewed 828 times
2
-
http://stackoverflow.com/a/21816603 outlines the currently used solution. (Standard handlebars has `@index`, but it seems not to be supported in Spacebars yet: https://github.com/meteor/meteor/issues/2587 ) – DRobinson Jun 14 '15 at 13:34
1 Answers
4
Currently no build-in support for that. If you iterating cursor, use this:
return Collection.find().map(function (doc, index, cursor) {
return _.extend(doc, {index: index + 1});
})
and use
{{#each .}}
{{index}}
{{/each}}

Firdaus Ramlan
- 1,146
- 8
- 11
-
I changed 'Collection' to the name of my collection, but it doesn't work. – Isaac Wasserman Jun 14 '15 at 13:39
-