Saving user data - JSON - localstorage

2 posts, 0 answers
  1. Niro
    Niro avatar
    8 posts
    Member since:
    Aug 2014

    Posted 16 Oct 2014 Link to this post

    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
  2. Martin Yankov
    Admin
    Martin Yankov avatar
    177 posts

    Posted 20 Oct 2014 Link to this post

    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.

     
Back to Top