Page 1 of 1

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

Posted: Thu Apr 06, 2017 8:39 am
by Deon

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


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

Posted: Thu Apr 06, 2017 2:32 pm
by Serhii Kulibaba

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...


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

Posted: Fri Apr 07, 2017 4:44 am
by Deon

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.


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

Posted: Fri Apr 07, 2017 3:15 pm
by Serhii Kulibaba

Glad to hear things are sorted out now!