var grandTotal;
angular.forEach($scope.gear, function(value, key) {
var rowTotal = value.amount * value.price;
console.log(rowTotal);
grandTotal += rowTotal;
});
console.log('grandTotal: '+grandTotal);
我有上述内容,我正在尝试获得赠款总额,似乎为我的grandTotal
更新:
var grandTotal = 0;
angular.forEach($scope.gear, function(value, key) {
var rowTotal = value.amount * value.price;
rowTotal = rowTotal.toFixed(1);
console.log(rowTotal);
grandTotal += rowTotal;
});
console.log('grandTotal: '+parseFloat(grandTotal));
这将返回
答案 0 :(得分:1)
如何使用vanilla javascript map
和reduce
函数?
基于您的目的的例子:http://jsfiddle.net/optyler/G2ZJa/