如何存储和访问站点的 JSON 数据?

发布于 2024-08-27 08:41:26 字数 265 浏览 3 评论 0原文

我正在构建一个 HTML/jQuery 站点,其中几乎所有内容都来自远程 JSON 数据。我很难想出一种在未来存储和访问数据的好方法(范围方面)。

目前,我编写了一个 jQuery 插件,可以在站点加载时获取 JSONP 数据。但我还有其他函数和 jQuery 插件需要访问这些数据。

这些数据应该存储在哪里以便其他函数和插件可以访问它?

它应该是一个全局变量吗?

如果重要的话,这个网站将只在 iPad 上运行,并且该网站的后端是在 Rails 中。

I'm buiding an HTML/jQuery site where almost all the content comes from remote JSON data. I'm having trouble coming up with a good way to store and access the data in the future (scope-wise).

Currently, I've written a jQuery plugin that gets the JSONP data when the site loads. But I have other functions and jQuery plugins that need to access this data.

Where should this data be stored so other functions and plugins can access it?

Should it be a global variable?

If it matters, this site will only run on the iPad and the back-end of the site is in Rails.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

太阳公公是暖光 2024-09-03 08:41:26

我建议您研究 Safari 和 Mobile Safari 支持的 HTML5 持久存储作为 SQL Lite DB。如果你决定不走这条路,我会选择 $().data() 而不是 JavaScript 中的全局变量。

I would suggest you investigate HTML5 persistant storage which is supported on Safari and Mobile Safari as a SQL Lite DB. If you decide not to go down that route I would opt for $().data() over a global variable in JavaScript.

情丝乱 2024-09-03 08:41:26

如果有可管理数量的 JSON 数据,您可以通过全局变量访问它。最好只有一两个具有嵌套属性的全局对象。

开发网页不像开发库我认为一些全局变量是可以接受的

If there's a manageable amount of JSON data you can access it through global variables. Preferably just one or two global objects with nested properties.

Developing a web page is not like developing a library I think a few globals are acceptable

生来就爱笑 2024-09-03 08:41:26

要在请求之间存储数据,您可以使用 HTML5 存储API。否则,只需传递保存数据的变量(引用)。

To store data between requests, you can use HTML5 Storage API. Otherwise just pass around the variable (reference) holding the data.

眼泪都笑了 2024-09-03 08:41:26

道场有。

如果你没有使用 jquery 的限制,那么也许你可以研究一下。

http://ajaxian.com/archives/dojostorage- Offline-access-and-permanent-client-side-storage

或者,您也可以将其存储在其他插件/函数可以访问的数组中。

Dojo has it.

If you do not have the constraint of using jquery, then maybe you can investigate it.

http://ajaxian.com/archives/dojostorage-offline-access-and-permanent-client-side-storage

Alternately, you could also probably just store it in an array that other plugins / functions can access it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文