0

我正在开发一个应用程序并且有一个关于填充表的问题,数据可能每年更改一次,所以我想避免网络调用数据库。

所以...

I'm using Jquery and Phonegap. I have lots of tables where I would consider coding statically, however, this data is likely to change once per year, so when I issue an update on the app I'd rather update one table then many different pages. I am wondering what approach to take to ensure updating will be easy, and at least I can have a "Template" and only update where the information is stored rather than HTML. Please impose all your knowledge and if you could point me towards a tutorial on implementing that method.

V/r, Kane

4

1 回答 1

0

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

长时间保留的数据是 localStorage 的良好候选者,这是一种广泛支持的功能。

http://caniuse.com/#feat=namevalue-storage

要将数据存储在 localStorage 中,您的代码将如下所示:

var s = JSON.stringify(data);
localStorage.setItem("key", s);

反转过程如下所示:

var s = localStorage.getItem("key");
data = JSON.parse(s);

数据可以存储在任何 javascript 对象中,包括对象数组,并且可以深度嵌套。以这种方式检索数据的调用非常快。如果您需要类似数据库的支持,我建议您查看诸如下划线或 lodash 之类的轻量级库。

http://underscorejs.org/

http://lodash.com/

WEBSQL 或 indexDB 之类的解决方案在浏览器支持方面仍然是零散的。

于 2013-11-06T04:22:01.253 回答