Hello,
I am building GENERIC SERVICE for in my app, for OFFLINE MODE functionality. Basing on APPERY DOC and some general guidelines in this forum I have created actually pretty simple generic service, just to understand the basics of it.
I wanted this implementation to be like regular query REST service with WHERE parameter, so I could use it in OFFLINE MODE whenever I need to get specific data.
I used ARRAY FILTER which seemed the simplest approach and just for testing purposes I used singe database ID in variable SEARCHED.
Unfortunately I can't make it work as intended. It keeps returning all data instead of just the one item with that ID.
So I have two questions:
1) What is wrong with this ARRAY FILTER implementation?
2) How do I create Generic Service parameter, so it will appear in mapping UI?
This is the custom JS for Generic Service:
$t.myimpl = $t.createClass(null, {
Code: Select all
init : function(requestOptions) {
this.__requestOptions = $.extend({}, requestOptions);
},
process : function(settings) {
if (this.__requestOptions.echo) {
settings.success(this.__requestOptions.echo);
} else {
var cdata = JSON.parse(localStorage.getItem("_Arttable_json_response"));
var searched = "52867b22e4b0be798fab779d";
var match = cdata.filter(function(item) {
return item._id === searched;
});
settings.success(cdata);
settings.success({});
return match;
}
settings.complete('success');
} });
This is how I pass data from database do local storage (on SUCCESS event):
var JSONresponse = JSON.stringify(data);
localStorage.setItem("_Arttable_json_response", JSONresponse);
This is my mapping: