hering
hering

Reputation: 1954

saving/loading settings in a SenchaTouch/PhoneGap -App with localStorage and display them in a form

How you should save/load settings in an app when you want to use the localStorage? Let's say we just want to save a username and a password.

Currently I know two options:

Which approach is better or is there even another, better approach to save/load settings and display them in a form?

Upvotes: 1

Views: 2117

Answers (1)

Yoh Suzuki
Yoh Suzuki

Reputation: 1455

I definitely agree with you that using a Sencha Touch model and store is overkill to store some settings. I recommend serializing your settings object with Ext.util.JSON.encode/decode.

Note: You won't be able to serialize the function members of an object though, much less the properties belonging to objects up its prototype chain, so you won't be able to serialize and deserialize an Ext model and have it work when you get it back. The best you could do is serialize the configuration for your Ext component and reconstitute it through its constructor after getting the configuration back.

For most simple settings objects, just serialize it and store it in a key in the local store. When you get to your page, get the settings object out and update your form. When you change a setting in the form, write it to the object. When you leave the page (onbeforeunload), write the object to localstore.

Upvotes: 3

Related Questions