我希望能够将不同的价格点传递给过滤器,但它现在定义的方式不起作用,除非我在例如priceArray.push(value.price)中进行硬编码
var priceSumUp = function ($log){
return function(arrayObj, nameValue){
var priceArray = [],
totalPrice = 0;
function sumUp(first, second){return first + second}
ng.forEach(arrayObj, function(value, key, obj){
priceArray.push(value.price);
});
totalPrice = priceArray.reduce(sumUp, 0);
//console.log(priceArray);
return totalPrice;
};
}
<div class="" ng-bind-html="vm.getisSelected | priceSumUp:price"></div>
答案 0 :(得分:0)
我认为你在寻找的是......
首先确保传递正确的参数。将其更改为
$scope.price = 'price'
// or
<div ng-bind="items | priceSumUp:'price'"></div>
接下来,您可以使用类似数组的ECMA对象属性来访问项目...
return function(arrayObj, v){
var priceArray = arrayObj.map(function(obj){
return obj[v]
})
...
}
请参阅我的plunker here这也可以说......
<div ng-bind="items | priceSumUp:'tax'"></div>