Recommended way to show loop counter


#1

What’s the preferred way to show loop counter/index with the each helper?

I’ve seen {{_view.contentIndex}}, but to me it looks very hacky since this private _view might change in any time, plus it’s zero-based only.

I guess I can implement view inside my each helper and do the computed property like:

counter: function(){
  this.get('_parentView.contentIndex') + 1;
}.property();

Am I going the right direction? Also is there way to implement computed property logic in ArrayController?


#2

You should just be able to use {{@index}} helper to get the current index.


#3

I’ve read it from handlebars doc & tried that before, but it just doesn’t seem to work. On what version are able to use this? Here’s my jsbin proving it doesn’t work


#4

You’re right sorry. I forgot that its not as simple as it looks.

Check this link out Each {{#each}} with index