I’m not 100% sure, but can’t you just do something like this?
Notice the {{total}} helper.
You where also missing the closing </li>
<template name="myTpl">
<ul>
{{#each data}}
<li>{{item}} | {{qty}} | {{price}} | {{amount}}</li>
// calculate sum of amount
{{/each}}
</ul>
Total {{total}} // echo sum that calculate above
</template>
Be sure to replace the “myCollection” with your collection.
Template.myTpl.helpers({
data: function(){
return data; // array of object
},
total: function() {
var sum = 0;
var cursor = MyCollection.find();
cursor.forEach(function(doc){
sum = sum + doc.price
});
return sum; // return total
}
});
It is not so slow. Do not afraid of Collection.find() or .find().fetch() in helpers. You just should worry about a huge rerenders on a client side because of the main realy slow thing is DOM manipulation.