我正在为电子商店设置购物车。我正在尝试从显示的产品中获取数据以创建订单清单。购物车是一个具有3个equals方法的对象,用于添加数量,名称和价格。但是只有一项工作。另外两个覆盖数据。我要库存的数据是字符串。var Cart = function () { this.cartListQte = {} this.products_names = {} this.products_prices = {}}//班级Cart.prototype = { //properties 'cartListQte': {}, 'products_names': {}, 'products_prices': {}, //methods //setter getter setCartListQte: function (cartListQte) { this.cartListQte = cartListQte; }, getCartListQte: function () { return this.cartListQte; }, setProducts_names: function (products_names) { this.products_names = products_names; }, getProducts_names: function () { return this.products_names; }, setProducts_prices: function (products_prices) { this.products_prices = products_prices; }, getProducts_prices: function () { return this.products_prices; }, //"push" new product pushed: function (productId,Qty){ this.cartListQte[parseInt(productId)]= parseInt(Qty); }, pushName: function (productId,nm){ this.products_names[parseInt(productId)]= nm; }, pushPrice: function (productId,prx){ this.products_prices[parseInt(productId)]= parseInt(prx); }}// gestion du panier函数addProductToCart(事件){//nouveau paniervar cart = new Cart; //on récupère le panier déjà enregistévar curentCart = JSON.parse(localStorage.getItem('panier')); //si il existe, on le manipuleif(curentCart != null){ cart.cartListQte = curentCart.cartListQte;}//récupération des nouvelles données à enregistrervar id = $(this).attr('productid');var quantity = $("[productIdQte="+id+"]").val();console.log(quantity);
2 回答
一只萌萌小番薯
TA贡献1795条经验 获得超7个赞
到那里,这应该可以解决问题。您忘记更新其他2个阵列。
if(curentCart != null){
cart.cartListQte = curentCart.cartListQte;
cart.products_names = curentCart.products_names;
cart.products_prices = curentCart.products_prices;
}
添加回答
举报
0/150
提交
取消