[英]jquery shopping cart delete table row from local storage
I'm trying to delete a row from a shopping cart (and the local storage) when I hit the 'x' button. 当我点击“ x”按钮时,我试图从购物车(和本地存储)中删除一行。
Here's what I have so far: 这是我到目前为止的内容:
for (i=0; i<numCart; i++){
var button = $('<td>'+infoCartItems[i].button+'</td>').addClass("checkoutTitles");
button.text('x');
row.append(button);
$(".cartTable").append(row);
}
here is what i have for my storage code: 这是我的存储代码:
var newItem= new Bun(pack, current, flavor2nd, flavor3rd, money);
var existingCartItems = JSON.parse(localStorage.getItem("itemsArray"))||[];
existingCartItems.push(newItem);
localStorage.setItem("itemsArray", JSON.stringify(existingCartItems));
Here's the code I used to delete the item from my shopping cart: 这是我用来从购物车中删除商品的代码:
$(".remove").on('click', function() {
// get the index of the row in the table
var index = $(this).parent().parent().index();
index = index - 1;
// remove item from table
$(this).parent().parent().remove();
// remove item from the cart local storage
var cart = JSON.parse(localStorage.getItem("itemsArray"));
cart.splice(index, 1);
localStorage.setItem("itemsArray", JSON.stringify(cart));
location.reload();
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.