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.
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.
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
To store data between requests, you can use HTML5 Storage API. Otherwise just pass around the variable (reference) holding the data.
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.
精彩评论