Function

Module: @ember/object
dependentKey
String
additionalDependentKeys
Array
optional array of additional dependent keys
callback
Function
returns
ComputedProperty
the filtered array

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.
1
function filterCallback(item, index, array);

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { set } from '@ember/object';
import { filter } from '@ember/object/computed';

class Hamster {
  constructor(chores) {
    set(this, 'chores', chores);
  }

  @filter('chores', ['doneKey'], function(chore, index, array) {
    return !chore[this.doneKey];
  })
  remainingChores;
}

let hamster = new Hamster([
  { name: 'cook', finished: true },
  { name: 'clean', finished: true },
  { name: 'write more unit tests', finished: false }
]);

hamster.remainingChores; // [{name: 'write more unit tests', finished: false}]