Page 1 of 1

With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Fri Sep 20, 2013 7:39 pm
by Garrett

I have a dynamically created array that is saved globally
code
window["myArray"] = [
{
"id":"00001",
"name":"Jim",
"gender":"male",
"shift":"1st",
"note":"this is a test note"
},
{
"id":"00002",
"name":"Susie",
"gender":"female",
"shift":"2st",
"note":"this is another test note"
}
];
/code

I want to display this data in a CollapsibleSet that I have added with the visual editor and have formatted it how I want it (I do not want to add the CollapsibleSet at runtime).

I have added a Generic (custom JavaScript implementation) service called "HandleItems" and have added the appropriate responses ("$" with sublevels = "id", "name", "gender", "shift", and "note").

I have mapped the responses visually to the CollapsibleSet including the "$" to iterate the collapsblocks (or items).

If I enable a sample echo response of:
code
[
{
"id":"00001",
"name":"Jim",
"gender":"male",
"shift":"1st",
"note":"this is a test note"
},
{
"id":"00002",
"name":"Susie",
"gender":"female",
"shift":"2st",
"note":"this is another test note"
}
]
/code

and invoke the service, it works as intended.

My question is...

How can I replace that sample echo response with the global array "window["myArray"] "?

Again, I require to use the visually added CollapsibleSet.
an implementation like this:
code
var data = ["Tinker", "Tailor", "Solder", "Spy"];
var listHtml = '<ul data-role="listview">';

for(var i=0; i<data&#46;length; i++)
{
listHtml += '<li><a href="#">'+data+'<&#47;a><&#47;li>';
}
listHtml += '<&#47;ul>';
var listElement = $(listHtml);
Appery('mobilecontainer1')&#46;append(listElement);
listElement&#46;listview();
/code
will not work.

Also, I am not using any backend, so saving the array to some database is not an option either. This is an "offline" app (no internet required).


With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Fri Sep 20, 2013 7:59 pm
by Maryna Brodina

Hi, could you clarify do you have problem with implementation of Generic service? Why don't you use Echo http://docs.appery.io/documentation/r...?


With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Fri Sep 20, 2013 8:19 pm
by Garrett

I would like to Control the Echo in runtime like in your link.
codeservice_instance_name&#46;__requestOptions&#46;echo = {"login":"a@b&#46;c", "password":"abc"}/code

so, assuming my Generic Service is called "StoreStep" and my JSON formatted global array is called "window["stepsArray"]"... How would I format the above code?
Like this?...
codeStoreStep&#46;__requestOptions&#46;echo = window["stepsArray"];/code

Additionally, where do I place this code? In StoreStep's "Success" event?


With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Fri Sep 20, 2013 8:27 pm
by Garrett

I figured it out!

I placed it in a JS for a button click before the service is actually invoked.

I also had to change it to this...
codeHandleItems&#46;__requestOptions&#46;echo = window["stepsArray"];/code
Where "HandleItems" is the actual name of the service and not what it's called on the page under the "data" tab.


With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Fri Sep 20, 2013 8:31 pm
by Maryna Brodina

Ok, thanks for update! Glad it's working!


With a Generic (custom JavaScript implementation) service, return the contents of an array that is saved globally

Posted: Thu Dec 19, 2013 10:59 am
by Ricardo Roque

Many thanks!

It is very important using the "actual" service name and not the "instance" name (under "Data" tab). I've lost several hours using the instance name with no success. :(