如何更新本地存储阵列的特定键值? [英] How do I update specific key value of the local storage array?
本文介绍了如何更新本地存储阵列的特定键值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像下面这样的本地存储阵列
I have a local storage array like below
pageItems = {"stationID":"145","categoryID":"-1","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}
我需要将 categoryID 值更新为 65
I need to update categoryID value to 65
pageItems = {"stationID":"145","categoryID":"65","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}
推荐答案
可以使用以下方法;
var pageItems = '{"stationID":"145","categoryID":"-1","pickupDate":"2014-04-22","pickupTime":"08:00","returnDate":"2014-04-23","returnTime":"08:00","milage":"false","miles":"","attributes":[[],[]],"additionals":[[],[]]}';
var json = JSON.parse(pageItems);
json.categoryID = 65;
pageItems_v2 = JSON.stringify(json);
这是一个工作演示:演示
Here is a working demo : Demo
这篇关于如何更新本地存储阵列的特定键值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文