Page 2 of 3

how to populate a listview from a json response?

Posted: Fri May 24, 2013 4:09 pm
by John Herdean

yes i thought i invoked the service before like you said and didnt work. Well, i did exactly as you said and now it works. Thanks.


how to populate a listview from a json response?

Posted: Mon Jul 29, 2013 3:40 am
by Brian6028327

I have the $ sign for the response array, but how do I reference it in JS?

Here's my mapping, and it works fine:
Image

Now, I'd like to use that in a piece of JS similar to this:
var response = JSON.stringify(data));
localStorage.setItem("json_response", response);

I'm guessing that "data" above should be "$" or something, but I haven't figured out how to make it work.


how to populate a listview from a json response?

Posted: Mon Jul 29, 2013 10:55 am
by Maryna Brodina

Hello! $ sign isn't connected with variables names in mapping. If you use your code on service success then variable where you retrieve entire responce is called "data". This code is correct:
codevar response = JSON.stringify(data));
localStorage.setItem("json_response", response); /code
If you want to add JS in mapping then value you map will be in "value" variable (no matter what field you map)


how to populate a listview from a json response?

Posted: Mon Jul 29, 2013 2:19 pm
by Brian6028327

I guess the part that is giving me trouble is that I am thinking all 4 fields under the $ sign could be saved as part of one arrayed variable.Would this be possible?


how to populate a listview from a json response?

Posted: Tue Jul 30, 2013 5:35 am
by Maryna Brodina

Hello! This is how it would be - will be saved an array containing 4 records.


how to populate a listview from a json response?

Posted: Tue Jul 30, 2013 2:20 pm
by Brian6028327

Hi,
I must be missing something dumb. Here's what I have, trying to use a local variable called 'testIt':

var response = JSON.stringify(data);
alert(response);
localStorage.setItem(testIt, response);
alert(testIt);

The first alert works with a nice string of all the data from the service, which is cool to see working, but the second alert does not return anything. Nothing happens, like it is not even there. I tried a few different combinations of quote marks and such, but with no luck.

BTW - Thanks for you help


how to populate a listview from a json response?

Posted: Tue Jul 30, 2013 5:51 pm
by Kateryna Grynko

Hi,

Here is the code:
codevar response = JSON.stringify(data);
alert(response);
localStorage.setItem( "testIt", response ); //you don't have "testit" variable so place "testit" in quotes to declare this is a string
alert( localStorage.getItem( "testit" ) ); //read saved data here./code


how to populate a listview from a json response?

Posted: Tue Jul 30, 2013 7:07 pm
by Brian6028327

Thank you! Thank you! That is exactly what I was missing.


how to populate a listview from a json response?

Posted: Wed Oct 09, 2013 7:33 am
by Kirit Vaghela

How to load listview with stored response data?


how to populate a listview from a json response?

Posted: Wed Oct 09, 2013 7:46 am
by Maryna Brodina

Hello! Could you clarify your question?