Function

mapBy (dependentKey, propertyKey) Ember.ComputedProperty public

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.

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]

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