In Handlebars I can easily do this:
{{#each elems}}
<li {{#if @first}}class="active"{{/if}}>{{@index}} this.name</li>
{{#each}}
I know that Ember doesn't support @data values, but I know that I can access index with the block syntax
{{#each elems as |elem index|}}
<li>{{index}} this.name</li>
{{/each}}
However, so far I haven't been able to replicate the #if @first syntax. I have tried to compute an property but I am unable to access the index inside the controller. How can I do that?
{{#each elems as |elem index|}}
<li class="{{isActive}}">{{index}} this.name</li>
{{/each}}
isActive: function () {
var idx = this.get("index"); // how to access index here?
return idx === 0 ? "active" : "";
}.property("elems.@each")
Aucun commentaire:
Enregistrer un commentaire