如何使用本地存储为单个键创建多个值 [英] How to create a multiple values for a single key using local storage
问题描述
众所周知,本地存储是一个键值对.尝试为单个键创建多个值.但是无法获得如何传递单个键的多个值.
As we all know local storage is a key value pair. Trying to create a multiple values to a single key. But unable to get how to pass the multiple values for a single key.
创建的内容很简单.
var value = "aa"
localStorage.setItem("testKey", value);
var test = localStorage.getItem("testKey");
alert(test);
现在,要实现的是testKey
应该具有aa, bb and cc
值.
Now here what want to achieve is testKey
should have aa, bb and cc
values.
如果可以的话,任何人都可以帮助我提供示例.
If it is possible can anyone please help me out with a sample.
注意:
localStorage值将适用于本机应用程序.
Will localStorage values work for native app.
推荐答案
这在localstorage中是不可能的.但是,您可以将JSON字符串存储为键的值,并进行一些后期处理,即可提取三个变量:
This is not possible with localstorage. However, you can store a JSON string as the value for the key, and with a little post-processing, you can extract your three variables:
var value = ["aa","bb","cc"]
localStorage.setItem("testKey", JSON.stringify(value));
var test = JSON.parse(localStorage.getItem("testKey"));
alert(test);
这篇关于如何使用本地存储为单个键创建多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!