Positional index in Ember.js collections iteration

前端 未结 8 798
梦如初夏
梦如初夏 2020-12-01 11:08

Is there a way to get positional index during iteration in ember.js?

{{#each itemsArray}}
     {{name}}
{{/each}}

I\'m looking for a way to

8条回答
  •  盖世英雄少女心
    2020-12-01 11:12

    I have modified a bit ud3323 solution using collection. Check here: http://jsfiddle.net/johngouf/WSwna/13/

    
    
    App = Ember.Application.create();
    App.peopleController = Ember.ArrayController.create({
     content: [ { name: 'Roy' }, { name: 'Mike' }, { name: 'Lucy' } ]
    });
    
    App.PersonView = Ember.View.extend({
     content: null,
     // Just to show you can get the current index here too...
     adjustedIndex: function() {
        return this.getPath('_parentView.contentIndex') + 1;
     }.property()
    });
    

    ​​

提交回复
热议问题