简体   繁体   English

如何在HTML5 / Jquery和Cordova / PhoneGap中存储首选项?

[英]How to store preference in HTML5/Jquery and Cordova/PhoneGap?

We develop mobile app utilising HTML5/JQuery and Cordova/PhoneGap. 我们使用HTML5 / JQuery和Cordova / PhoneGap开发移动应用程序。

We have an HTML page for handling "site preference" ie Australia, India, Pakistan etc etc. We would like to store that (per device basis). 我们有一个用于处理“网站偏好”的HTML页面,例如澳大利亚,印度,巴基斯坦等。我们希望存储该信息(基于设备)。 What is the best way to store this? 最好的存储方式是什么? We know that HTML5 has "localstorage" but doesn't mean the life of this data is only stored when the webkit application running. 我们知道HTML5具有“本地存储”功能,但并不意味着仅在Webkit应用程序运行时才存储此数据的寿命。 So if the application is off means that the device will lost the information that being stored. 因此,如果应用程序关闭,则意味着设备将丢失正在存储的信息。 Is that right? 那正确吗?

We want to have a simple like Cookies concept in the browser that we can just drop and read from there. 我们希望在浏览器中有一个简单的类似Cookies的概念,我们可以在其中拖放并读取。 But obviosually won't work if we ported to Cordova/PhoneGap. 但是,如果我们移植到Cordova / PhoneGap,显然不会起作用。 Any ideas how to store this? 有什么想法如何存储吗?

Thanks 谢谢

Best way to store simple preferences using LocalStorage W3C API , All values will be stored on per-device basis and that API is very easy to work with. 使用LocalStorage W3C API存储简单首选项的最佳方法,所有值将按设备存储,并且该API非常易于使用。

function getCountry() {
   var currentCountry = window.localStorage.getItem('country');
   return currentCountry;
}

function setCountry(country) {
   window.localStorage.setItem('country', country);
}

If you need storing structured data, you could look at the other storage options which are supported by the Cordova 如果您需要存储结构化数据,则可以查看Cordova支持的其他存储选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM