2

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.

Isaac Wasserman
  • 1,461
  • 4
  • 19
  • 39
  • 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 Answers1

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