Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Store data from DB to Local Storage Array and then retrieve from local storage to List

Hi

Please can you assist.
I have data in a db which I want to add to a local storage array.

This is my Storage Model
Image
Image

  1. How do I use a REST service to insert the data from the DB into this Storage model? Do I just use a the normal Rest Service and Mappings?

  2. Once I have the data in the local storage, I now need to populate a List. Do I create a Generic REST Service to do this?

    This is the generic service code I have created but does not seem to work.

    Appery.getRides = Appery.createClass(null, {

    init : function(requestOptions) {
    this.__requestOptions = $.extend({}, requestOptions);
    },

    process : function(settings) {
    settings.beforeSend(settings);
    if (this.requestOptions.echo) {
    settings.success(this.requestOptions.echo);
    } else {
    var cdata = localStorage.getItem("RideList");
    settings.success(JSON.parse(cdata));
    }
    settings.complete('success');
    }

    });

    Many thanks

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Store data from DB to Local Storage Array and then retrieve from local storage to List

Hello Deon,

Yes, it is possible to use a mapping for that, or save the response with a custom JS code on the Success event: https://docs.appery.io/docs/appbuilde...

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Store data from DB to Local Storage Array and then retrieve from local storage to List

Hi Serhii

Thanks.
The problem was also in the generic service..
This line...
settings.success(JSON.parse(cdata));
should actually be
settings.success(cdata);

No need to parse the data.

Return to “Issues”