Page 1 of 1

Mapping items from local storage to list component

Posted: Wed Oct 16, 2013 8:58 am
by kavya

I am invoking a service and excecuting a javascript in its success event where I am saving the JSON response of the service into local storage.

Now I want to parse the JSON response from the local storage and I want to display the items from it to the list component. How can this be done?


Mapping items from local storage to list component

Posted: Wed Oct 16, 2013 10:38 am
by Kateryna Grynko

Hi,

You can do the following:
codevar obj = JSON.parse(json);/codewhere json is a string with json content.

Why don't you map to List directly? This approach is more complex.


Mapping items from local storage to list component

Posted: Wed Oct 16, 2013 11:46 am
by kavya

Thanks for the reply Katya. But the issue is I need this response in many pages.So I need to use local storage for this. In each page, I need a different item from the response to be mapped to the list.

So how can I map the items from local storage on to a clickable list??


Mapping items from local storage to list component

Posted: Wed Oct 16, 2013 1:11 pm
by Kateryna Grynko

Hi,

You can map the array with images to Grid, and map the array item value to a Grid item. Add the following code in array item mapping:
codetest1 = localStorage.getItem("test");
test = JSON.parse("["+test1+"]");
if (test !== null){
test.push(value);
} else {
test = new Array(value);
}

localStorage.setItem("test", test + "");/code
After the service works successfully you get an array saved in "test" localStorage variable. Then you can get the array items as shown above.