无法通过ID值删除sessionStorage

时间:2019-02-13 00:20:14

标签: jquery session-storage

我目前有以下代码,可以将项目添加到sessionStorage并可以正常工作

In [91]: dblsort= np.argsort(sort_seq, axis=1)
In [92]: dblsort
Out[92]: 
array([[1, 0, 2],
       [2, 0, 1],
       [1, 2, 0]])
In [93]: res = np.zeros_like(letters)
In [94]: np.put_along_axis(res, dblsort, letters, axis=1)
In [95]: res
Out[95]: 
array([['a', 'b', 'c'],
       ['a', 'b', 'c'],
       ['a', 'b', 'c']], dtype='<U1')

我遇到的问题是,当我尝试从sessionStorage删除项目时,它会到达以下行:

  

for(var i = 0; i

然后跳过其余部分,任何人都可以看到我的新眼睛

<script>
    $(document).ready(function () {
        $('.btnProduct').on('click',function (e) {
            e.preventDefault();

            var id = $(this).data("id");
            var title = $(this).data("title");
            var rawPrice = $(this).data("price");
            var cart = sessionStorage.getItem("cart");
            var obj = [];
            if (cart) {
                obj = JSON.parse(cart);
            }
            obj.push({ "id": id, "title": title, "price":rawPrice });
            sessionStorage.setItem("cart", JSON.stringify(obj));
        });
        function populateContainer() {
            var retrieveCartFromSessionStorage  = sessionStorage.getItem("cart");
            var displayCartInSessionStorage     = JSON.parse(retrieveCartFromSessionStorage);

            var total = 0;
            for (var p in displayCartInSessionStorage) {
                if (displayCartInSessionStorage.hasOwnProperty(p)) {
                    $(".itemsInCart").append('<p>' + displayCartInSessionStorage[p].title + ' ' + '£' + displayCartInSessionStorage[p].price.toFixed(2) + '</p>');
                    total += displayCartInSessionStorage[p].price;
                }
            }
            var displayTotal = total;

            var displayTotalPlusPriceOfAircraft = displayTotal += 100000;
            $("#displayTotal").text(`Total £${displayTotalPlusPriceOfAircraft.toFixed(2)}`);
        }

        populateContainer();

    });
</script>

0 个答案:

没有答案