#6 Filter Arrays

Let’s say you have a collection of Articles and you want to filter them. One of the easiest way to do this using the built-in computed helpers.

publishedArticles : Ember.computed.filterBy(‘articles’, ‘status’, ‘active’),
draftArticles : Ember.computed.filterBy(‘articles’, ‘status’, ‘draft’),

The above collections will automatically re-compute as the “articles” array changes, so if you change an article status in articles from active to draft, it will reflect accordingly in each computed array, here is an example https://ember-twiddle.com/fa50909f2683d7335fc8b3fb0d9009ab?openFiles=controllers.application.js%2C


Explore more at http://emberjs.com/api/classes/Ember.computed.html

Originally published at Ember Daily Tips.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.