Ember.computed.max()

max (dependentKey) Ember.ComputedPropertypublic

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

A computed property that calculates the maximum value in the dependent array. This will return -Infinity when the dependent array is empty.

let Person = Ember.Object.extend({
  childAges: Ember.computed.mapBy('children', 'age'),
  maxChildAge: Ember.computed.max('childAges')
});

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

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

If the types of the arguments are not numbers, they will be converted to numbers and the type of the return value will always be Number. For example, the max of a list of Date objects will be the highest timestamp as a Number. This behavior is consistent with Math.max.

Parameters:

dependentKey String

Returns:

Ember.ComputedProperty
computes the largest value in the dependentKey's array
doc_EmberJs
2016-11-30 16:51:17
Comments
Leave a Comment

Please login to continue.