Function

filterBy (dependentKey, propertyKey, value) ComputedProperty public

Module: @ember/object
import { filterBy } from '@ember/object/computed';
dependentKey
String
propertyKey
String
value
*
returns
ComputedProperty
the filtered array

Filters the array by the property and value.

Example:

import { set } from '@ember/object';
import { filterBy } from '@ember/object/computed';

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

  @filterBy('chores', 'done', false) remainingChores;
}

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

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

Classic Class Example:

import EmberObject from '@ember/object';
import { filterBy } from '@ember/object/computed';

let Hamster = EmberObject.extend({
  remainingChores: filterBy('chores', 'done', false)
});

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

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

© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/filterBy