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

54 views Asked by At

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

2

There are 2 answers

1
Joachim H. Skeie On BEST ANSWER

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}}
0
yuva 443 On

We can use helpers also. Here is an example.