jquery 购物车从本地存储中删除 table 行

jquery shopping cart delete table row from local storage

当我点击 'x' 按钮时,我试图从购物车(和本地存储)中删除一行。

这是我目前的情况:

for (i=0; i<numCart; i++){

    var button = $('<td>'+infoCartItems[i].button+'</td>').addClass("checkoutTitles");
    button.text('x');
    row.append(button);
    $(".cartTable").append(row);

}

这是我的存储代码:

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));

这是我用来从购物车中删除商品的代码:

$(".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();

});