Ember.computed.filter()

filter (dependentKey, callback) Ember.ComputedPropertypublic

Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:248

Filters the array by the callback.

The callback method you provide should have the following signature. item is the current item in the iteration. index is the integer index of the current item in the iteration. array is the dependant array itself.

function(item, index, array);
let Hamster = Ember.Object.extend({
  remainingChores: Ember.computed.filter('chores', function(chore, index, array) {
    return !chore.done;
  })
});

let hamster = Hamster.create({
  chores: [
    { name: 'cook', done: true },
    { name: 'clean', done: true },
    { name: 'write more unit tests', done: false }
  ]
});

hamster.get('remainingChores'); // [{name: 'write more unit tests', done: false}]

Parameters:

dependentKey String
callback Function

Returns:

Ember.ComputedProperty
the filtered array
doc_EmberJs
2016-11-30 16:51:14
Comments
Leave a Comment

Please login to continue.