I have #each loop in my ember app and want to know index of loop, so I try to using {{@index}} like this :
<script type="text/x-handlebars" data-template-name="column"> <ul> {{#each item in controller}} {{@index}} {{item-rows currentItem=item}} {{/each}} </ul> </script>
But in chrome, I get this error:
Uncaught SyntaxError: Unexpected token , handlebars.js:1457
My ember.js version is rc8 and handlebars is 1. I need a solution to find index of #each.
Advertisement
Answer
You can get the contentIndex from itemViewClass
of the #each
helper
{{#each itemViewClass="Em.View"}} <h3 class="row">{{name}} - <small>{{view.contentIndex}}</small></h3> {{/each}}