Ember.computed.uniqBy()

uniqBy (dependentKey, propertyKey) Ember.ComputedPropertypublic

Defined in packages/ember-runtime/lib/computed/reduce_computed_macros.js:379

A computed property which returns a new array with all the unique elements from an array, with uniqueness determined by specific key.

Example

let Hamster = Ember.Object.extend({
  uniqueFruits: Ember.computed.uniqBy('fruits', 'id')
});
let hamster = Hamster.create({
  fruits: [
    { id: 1, 'banana' },
    { id: 2, 'grape' },
    { id: 3, 'peach' },
    { id: 1, 'banana' }
  ]
});
hamster.get('uniqueFruits'); // [ { id: 1, 'banana' }, { id: 2, 'grape' }, { id: 3, 'peach' }]

Parameters:

dependentKey String
propertyKey String

Returns:

Ember.ComputedProperty
computes a new array with all the unique elements from the dependent array
doc_EmberJs
2016-11-30 16:51:21
Comments
Leave a Comment

Please login to continue.