Function
sum (dependentKey) ComputedProperty public
Module: | @ember/object |
---|
Defined in packages/@ember/object/lib/computed/reduce_computed_macros.js:56
Available since v1.4.0
import { sum } from '@ember/object/computed';
- dependentKey
- String
- returns
- ComputedProperty
- computes the sum of all values in the dependentKey's array
A computed property that returns the sum of the values in the dependent array.
Example:
import { sum } from '@ember/object/computed'; class Invoice { lineItems = [1.00, 2.50, 9.99]; @sum('lineItems') total; } let invoice = new Invoice(); invoice.total; // 13.49
Classic Class Example:
import EmberObject from '@ember/object'; import { sum } from '@ember/object/computed'; let Invoice = EmberObject.extend({ lineItems: [1.00, 2.50, 9.99], total: sum('lineItems') }) let invoice = Invoice.create(); invoice.total; // 13.49
© 2020 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://api.emberjs.com/ember/3.25/functions/@ember%2Fobject%2Fcomputed/sum