This is a migrated thread and some comments may be shown as answers.

Saving user data - JSON - localstorage

1 Answer 203 Views
Apache Cordova
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Niro
Top achievements
Rank 1
Niro asked on 16 Oct 2014, 10:35 AM
Hi All,

I have a list of saved items in my kendo mobile app which is shown to the user using a listview, the listview is populated by a datsource and i add items to this datasource from different views on the app based on the user clicking save item. What is the best way to save the data on this datasource to be persistant when the user closes and starts the app again ?

should i be using localstorage ? my understanding is that this is treated as cached data and ios does not back it up ? is this the right way to go ?

this is what my datasource looks like so far although i cant get it to fire the create method when i use .add

new kendo.data.DataSource({
                                transport: {
                                    read: function (options) {
                                        //
                                        options.success(JSON.parse(localStorage.getItem('xxx')));
                                    },
                                    create: function (options) {
                                        alert('test storage create');
                                        localStorage.setItem('xxx',options.data);
                                    }
                                    },
                                schema: {
                                    model: {
                                        id: "id",
                                        fields: {
                                            id: { type: "string" },
                                            name: { type: "string" },
                                            picurl: { type: "string" },
                                            type: {type: "string"}
                                        }
                                    }
                                }
                  }),

Cheers
Niro

1 Answer, 1 is accepted

Sort by
0
Martin Yankov
Telerik team
answered on 20 Oct 2014, 12:40 PM
Hi Niro,

You can find information regarding the three ways of storing information locally in a Cordova app here. They are LocalStorage, IndexedDB and WebSQL. All have their pros and cons and all of them get backed up to iCloud. In fact, you can have problems with that since according to their guidelines Apple rejects all apps that back up data not generated by the user. If you are using any of the three storage methods to persist settings or user data, you should manually state that you don't want them to be backed up. In short, local storage gets backed up to iCloud by default.

Regarding your second problem, you trigger the create, destroy or update functions when you call the sync() method. This allows you to create, update or delete bulk data. In your current scenario it is best for you to call the .sync() method after every .add().

I hope this works for you and the information was helpful. Let me know should you need anything else.

Regards,
Martin Yankov
Telerik
 

Visit the Telerik Verified Plugins Marketplace and get the custom Cordova plugin you need, already tweaked to work seamlessly with AppBuilder.

 
Tags
Apache Cordova
Asked by
Niro
Top achievements
Rank 1
Answers by
Martin Yankov
Telerik team
Share this question
or