Page 1 of 1

generic service array mapping

Posted: Tue May 08, 2018 8:19 pm
by Bernie

I created a generic service based of a JSON.stringified array stored in a localstorage variable.

Here is the javascript code of my generic service:

Appery.getOffline = Appery.createClass(null, {

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

process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.requestOptions.echo);
} else {
//console.log('Default implementation is used. Please define your own.');

// load JSON data from local storage

var cdata = localStorage.getItem("offline1");

//This is how the content of the local storage looks like
//[{"column1":"1","column2":"10","column3":"100"},{"column1":"2","column2":"20","column3":"200"}]

// pass the JSON to the service, for output mapping
settings.success(JSON.parse(cdata));

}
settings.complete('success');
}

});

Unfortunately the mapping into a list element won't work.
Any ideas on what could solve the problem would be great.
Thank you in advance

Image


generic service array mapping

Posted: Wed May 09, 2018 2:39 pm
by Bernie

This is how it works:

Appery.getOffline = Appery.createClass(null, {

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

process: function(settings) {
if (this.requestOptions.echo) {
settings.success(this.requestOptions.echo);
} else {

Code: Select all

 // load JSON data from local storage 
 var cdata = localStorage.getItem("offline1"); 
 //This is how the content of the local storage looks like 
 //[{"column1":"1","column2":"10","column3":"100"},{"column1":"2","column2":"20","column3":"200"}] 

 var cdata2 = JSON.parse(cdata); 

 // pass the JSON to the service, for output mapping 
 settings.success(cdata2); 

}
settings.complete('success');
}

}); Image


generic service array mapping

Posted: Thu May 10, 2018 2:15 pm
by Serhii Kulibaba

Hello,

Thank you for the update! Glad it works now!