Function

dependentKey
String
propertyKey
String
returns
ComputedProperty
an array mapped to the specified key

Returns an array mapped to the specified key.

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

let Person = EmberObject.extend({
  childAges: mapBy('children', 'age')
});

let lordByron = Person.create({ children: [] });

lordByron.get('childAges'); // []
lordByron.get('children').pushObject({ name: 'Augusta Ada Byron', age: 7 });
lordByron.get('childAges'); // [7]
lordByron.get('children').pushObjects([{
  name: 'Allegra Byron',
  age: 5
}, {
  name: 'Elizabeth Medora Leigh',
  age: 8
}]);
lordByron.get('childAges'); // [7, 5, 8]