Search code examples
ember.jsgrunt-ember-templates

Ember.js: How to dispaly only a part of model in template?


In a template:

{{#each displayVideos}}   

Index:   {{_view.contentIndex}}

{{/each}}

It will display all item in model.

But I want to display only some item depend on index(ex: Display item if index%2==0).

Any idea about it? Thanks


Solution

  • Create a computed property in your controller, that will only return every second row, and iterate over that instead...

    Something like:

    App.MyController = Ember.ObjectController.extend({
        everySecondRow: function() {
            //code to only return every second row
        }.property('model')
    });
    

    Then in your template:

    {{#each controller.everySecondRow}} ... {{/each}}