我正在使用 simplecartjs 为在线商店提供动力。它将数据存储在本地存储中,如下所示:
{"SCI-1":{"quantity":1,"id":"SCI-1","price":20,"name":"Mattamusta -teippi","size":"Tyhjä"},"SCI-3":{"quantity":1,"id":"SCI-3","price":19,"name":"Mohawk .vaimennusmatto 48 x 39cm"},"SCI-5":{"quantity":2,"id":"SCI-5","price":8,"name":"Car Speaker -hajuste","color":"Green Tea"},"SCI-7":{"quantity":1,"id":"SCI-7","price":50,"name":"Asennuspaketti"},"SCI-9":{"quantity":1,"id":"SCI-9","price":30,"name":"Quartz-kalvot","color":"Yellow","size":"50cm x 30cm"},"SCI-11":{"quantity":1,"id":"SCI-11","price":30,"name":"Quartz-kalvot","color":"True Blue","size":"50cm x 30cm"}}
我想在它关闭之前添加这条线。
"SCI-12":{"quantity":1,"id":"SCI-12","price":5,"name":"Toimituskulut"}
但是,产品的数量将取决于用户,因此SCI-12必须随着项目的数量而增长。
编辑实际上,它不必使用SCI-1,它可以是任何东西,只要它在项目之后。
EDIT2 这就是我正在尝试的......但没有运气。
$("#matkahuolto").click(function(){
var value_object = '"Toimituskulut":{"quantity":1,"id":"Toimituskulut","price":5,"name":"Toimituskulut"}';
var json_object = JSON.parse(localStorage.your_json); // convert string to object
json_object["simpleCart_items"] = value_object; // add value
localStorage.your_json = JSON.stringify(json_object); // store it again.
});
$("#posti").click(function(){
var json_object = JSON.parse(localStorage.your_json); // convert string to object
json_object["simpleCart_items"] = value_object; // add value
localStorage.your_json = JSON.stringify(json_object); // store it again.
});
EDIT3 本地存储的屏幕截图。