I'm beginner in Emberjs,
I want to calculate the total amount in the added item list.
For example:
(03) items added in list ------------------------ Item-1 3,000.00 Item-2 4,000.00 Item-3 3,000.00 ------------------------- Total 10,000.00 Print -------------------------
How to create the view and controller in emberjs for calculate the total amount?
How to create the PDF file and print the same output as PDF format?
Thanks advance. :)
The aggregation methods in Ember.Enumerables are handy for this type of thing. I've created a jsBin demonstrating how to use reduce() in this case. You can create a computed property for the total on your controller that sums the values of each record in your model. Note that passing 0 as the second parameter (initialValue) will seed reduce() with an integer and help you avoid the string concatenation issues you were seeing.
total: function () {
return this.get('model').reduce(function (previousValue, item, index, enumerable) {
return previousValue + item.value;
}, 0);
}.property('model.@each')
(Your second question is unrelated, but you might want to take a look at jsPDF.)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments