[英]Cordova LocalStorage doesn't work
Do I have to install a plugin in Android platform? 我必须在Android平台上安装插件吗? I cannot find anything for a plugin in the Cordova documentation.
我在Cordova文档中找不到任何插件。
function save(){
window.localStorage.setItem("key", "value");
var keyname = window.localStorage.key(i);
var value = window.localStorage.getItem("key");
alert (value);
}
Dario, since you are using LocalStorage
there is no plugin required. 达里奥,由于您使用的是
LocalStorage
,因此无需插件。 I am not sure about your statement: 我不确定您的说法:
window.localStorage.key(i);
Where is i
set? i
在哪里设置?
I have a UTIL class I use with Getter / Setter. 我有一个与Getter / Setter一起使用的UTIL类。 Here is the
js
for that. 这是用于此的
js
。 Hope this helps. 希望这可以帮助。
var util = function () {
return {
//-----------------------------------
set: function (key, value) {
localStorage.setItem(key, JSON.stringify(value));
},
//-----------------------------------
get: function (key, defaultVal) {
var value = JSON.parse(localStorage.getItem(key));
if (value === null) value = defaultVal;
return value;
},
}; //End Return
}(); //End Closure
//Sample Set
util.set("downloadFlag", 1);
//Sample Get (with a default value 0 if null is found)
var fileDownloadedFlag = util.get("downloadFlag", 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.