I have #each loop in my ember app and want to know index of loop, so I try to using {{@index}} like this :
JavaScript
x
9
1
<script type="text/x-handlebars" data-template-name="column">
2
<ul>
3
{{#each item in controller}}
4
{{@index}}
5
{{item-rows currentItem=item}}
6
{{/each}}
7
</ul>
8
</script>
9
But in chrome, I get this error:
JavaScript
1
2
1
Uncaught SyntaxError: Unexpected token , handlebars.js:1457
2
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
JavaScript
1
4
1
{{#each itemViewClass="Em.View"}}
2
<h3 class="row">{{name}} - <small>{{view.contentIndex}}</small></h3>
3
{{/each}}
4