Modify localstorage?

前端 未结 3 2002
暖寄归人
暖寄归人 2021-01-05 18:26

I\'m using simplecartjs to power an online store. It stores it\'s data in local storage, which looks like this:

{\"SCI-1\":{\"quantity\":1,\"id\":\"SCI-1\",\         


        
3条回答
  •  日久生厌
    2021-01-05 19:04

    Or you could let http://rhaboo.org do the heavy lifting and write:

    var store = Rhaboo.persistent("My Cart");
    if (store.cart === undefined) 
      store.write('cart', []);
    //otherwise it must have data in from before
    
    $("#matkahuolto").click(function(){
      store.cart.push ({
          "quantity":1,  "id":"Toimituskulut",
          "price":5,     "name":"Toimituskulut"  });
    });
    
    $("#show").click(function(){ console.log( 
        store.cart.map(function (i) {
          return i.quantity + " " + i.id + "s at " + i.price + " each"
        }).join(' plus '); );  
     });
    

    BTW, I wrote rhaboo.

提交回复
热议问题