Page 1 of 1

map variable to grid?

Posted: Sun Jul 21, 2013 8:52 am
by Jochen Van den Bossche

Mapping the result from a service to a grid (etc) is implemented nicely.
My app is going to be 100% off-line (exceptional huh!).
The main things in there are going to be two variables (either arrays-of-similar-objects or objects-that-contain-several-similar-objects).
Is there a way to use service like mapping on such structures?
That way, a new version of the app with only updated variables would be all that is needed to extend the functionality.

Now, I have to put every item manually in predefined grids. When there is a new item (= new app version), I'd have to change all the grids, instead of just one variable... (And how do I loop over a grid? looping over an array or the objects in an object is easy)

I have the feeling that "Create New Service" / "Generic (custom JavaScript implementation)" is the start of the right path to the solution (possibly involving using the "Echo" system always) but I can not find any example about that. What does the event look like to call such a service? What needs to be in the "Generic JavaScript" code apart from my variable?


map variable to grid?

Posted: Sun Jul 21, 2013 9:18 am
by Jochen Van den Bossche

I think I found (part of) the solution myself.
Here is how I created my Generic Service:
1) "Create New" / "Service"
2) choose "Generic (custom JavaScript implementation)" and click the blue button
At first I was a bit confused by all the options there (you can skip over these to read on. I do not expect answers to these questions):
a) must I "Add custom implementation"? What should be in there? Just my variable? Some kind of execute() method?...
b) What do I set for Request? How do I call my execute()?...
3) I skipped down to the Response-tab (Since I know what I need).
There, I clicked the "Automatically Create from Sample Response"-button and pasted my array definition, clicked the blue button and finally the close-button. Tada! $ and my fields at a lower level, just like I saw in the DataBase service. great!
4) Then I opened the Echo-tab. Checked the box and once more pasted my array. So the service will always send me what i want. If I want to change the data, I suppose that I only need to change the Echo definition, right?
5) then to the Page, Data, Mapping, ... just like for a database service :-)
6) test :-)

Now "only" getting the result into local storage and working(*) with it...
That 'working' will consist never of adding or removing items from the arrays, but only of modifying the attributes of the objects contained in the arrays and doing calculations with them.)


map variable to grid?

Posted: Sun Jul 21, 2013 1:27 pm
by Jochen Van den Bossche

After a break to see the new king on his throne, I found another part of the answers to my own questions:
http://docs.appery.io/tutorials/build...
contains a section "Create generic service", which explained a lot (though I won't need either databases, hopefully).
The key, this time, was to use (when creating the Generic Service) the "Add Custom Implementation" and then not "Select JavaScript" (as I did at first, since that was where my array already was), but use "New Java Script Name". Clicking on "Open Implementation" shows what I was looking for: an outline of code of what a service is supposed to be (and enough keywords to find a sample in the doc)


map variable to grid?

Posted: Sun Jul 21, 2013 1:51 pm
by Illya Stepanov

Hi Jochen, nice to hear that our documentation can help. Thanks!

But I'm not sure I understand the question that you are asking?


map variable to grid?

Posted: Mon Jul 22, 2013 6:42 pm
by Jochen Van den Bossche

Well: A service returns a formatted collection of data, right. Appery.io has a nice interface to map that collection to eventually generate (for example) multiple rows in a grid.
Now, a variable can just as well be a formatted collection of data. So why not provide a similar interface to map such things.
Eventually I found out how to do it, using the generic interface: just let the success function return that variable (albeit in JSON format).

In short my program does multiple iterations over: create an array of objects, JSON.stringify() it, localStorage.setItem() that and return it as settings.success() = display. Next, localStorage.getItem(), JSON.eval(), loop over the arrays to do something with them and then back to stringify() etc.

I suggest you turn it into a tutorial. Services are (very) nice, but not what is needed all the time...

Ow, if you happen to find a way to use (instead of an array) objects that contain multiple similar objects, that would be great: much easier to identify an item, instead of having to loop over arrays each time to find a single element.


map variable to grid?

Posted: Mon Jul 22, 2013 7:57 pm
by Maryna Brodina

Hello! Why don't you try to use just rest service with Echo response instead of GenericService http://docs.appery.io/documentation/a.... It should be much more easier in your case - you should specify what you need to get and call the service. GenericService needs to be used for preprocessing more complex data.