12
{#each controller.content.assetAllocation.class}}
    {{@index}}
{{/each}}

I'm trying to run the code above, which is supposed to output the index of the array, but it produces an error saying: "Uncaught SyntaxError: Unexpected token , "

JJJ
  • 2,889
  • 3
  • 25
  • 43

2 Answers2

16

Solution is not as nice as I'd hoped, but this works:

{#each controller.content.assetAllocation.class}}
    {{_view.contentIndex}}
{{/each}}
JJJ
  • 2,889
  • 3
  • 25
  • 43
4

Here's my way:

{#each controller.content.assetAllocation.class as |item index|}}
    {{index}} - {{item}}
{{/each}}

The index is Zero-based numbering. So if you want to change it, just add an helper like this:

Ember.Handlebars.registerBoundHelper("indexBase1", function (value, options) {
        return value + 1;
});

And using it:

{#each controller.content.assetAllocation.class as |item index|}}
    {{indexBase1 index}} - {{item}}
{{/each}}
Trong Mac
  • 41
  • 3