我想获得所有购物车数量,但我得到错误。可以帮帮我吗?有关详细信息,请Preview
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
答案 0 :(得分:1)
在范围内创建方法
喜欢这个
$scope.totalItem = function() {
return $scope.cart.map(function(x) {
return +x.count;
}).reduce(function(a, b) {
return a + b;
}, 0);
}
现在在视图中添加此方法
{{totalItem()}}
的 DEMO
强>