Hey,
> I'm trying to figure out how to use the local storage for storing some
> unchanging data if possible. I first check for the support of the storage
> and then attempt to get the model from the offline storage. If it does not
> exist I grab it from a Json store. This works but the next time I load the
> site I thought the data should now come from the offline store but it is
> not. Is there something I am missing here? I can't see a way to 'save' the
> json data to the offline store which seems like what is missing.
You don't have to save the data because thats done automatically. But sharing
your code snippet shows the problem:
> if (qx.core.Environment.get("html.storage.local"))
> {
> console.log("local storage exists!");
> ///use local storage
> theStore = new qx.data.store.Offline(url, "local");
> if(theStore.getModel() == null)
> {
> console.log("loading from json data");
Here start the problem! You are creating an JSON store which load the data via
XHR which is good so far.
> var jsonStore = new qx.data.store.Json(url);
In that line, you set the model of the offline store to the json store model.
That sounds good as well. The bad thing is, that the loading via XHR is
asynchronous which means, every time you come to that line, the model hasn't
been loaded yet so the getModel method returns null. Thats why you always get
the null as model on reload.
> theStore.setModel(jsonStore.getModel());
Instead of just setting the model, you could set up a binding which then takes
care of the asynchronous loading for you:
jsonStrore.bind("model", theStore, "model");
> }
> else
> {
> console.log("Local storage! Loaded from cache");
> }
> }
> else
> {
> console.log("No local storage - loading from json data");
> theStore = new qx.data.store.Json(url);
> }
Regards,
Martin
------------------------------------------------------------------------------
Systems Optimization Self Assessment
Improve efficiency and utilization of IT resources. Drive out cost and
improve service delivery. Take 5 minutes to use this Systems Optimization
Self Assessment. http://www.accelacomm.com/jaw/sdnl/114/51450054/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel