1
で作業されていない私のコードははカートから削除ここでAngularJS
$scope.cart = [];
$scope.addToCart = function (cat) {
var found = false;
$scope.cart.forEach(function (item) {
if (item.id === cat.product_id) {
item.quantity++;
found = true;
}
});
if (!found) {
$scope.cart.push(angular.extend({quantity: 1}, cat));
}
};
//remove from cart function
$scope.removeToCart = function (cat) {
console.log(cat.product_id);
var found = false;
$scope.cart.forEach(function (item) {
if (item.id === cat.product_id) {
item.quantity--;
found = true;
}
});
if (!found) {
$scope.cart.push(angular.extend({quantity: 1}, cat));
}
};
console.log($scope.cart);
$scope.getCartPrice = function() {
var total = 0;
$scope.cart.forEach(function (cat) {
total += cat.finalprice * cat.quantity;
});
return total;
};
あなたは "cat"で渡しているものといっしょにもっと凝ったことができますか?それがオブジェクトであれば、その詳細を共有できますか?今質問が不明確になっています。また、どのように削除関数が呼び出されているかを示すことができますか? –
私は猫でのproduct_idを渡しMA、無それはオブジェクト \t <ラベルID = "{{cat.product_id}}"> 0 – Bhautik129