Function

Module: @ember/object
import { mapBy } from '@ember/object/computed';
dependentKey
String
propertyKey
String
returns
Ember.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
let Person = Ember.Object.extend({
  childAges: Ember.computed.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]