Page 1 of 1

problem loading array

Posted: Thu May 30, 2013 11:04 am
by Michael4771079

Hi
I have an array than I calling from db, array is in local storage I can see it in the dom so the rest is working,

but I seem to be missing some js to populate the component from local storage variable companiesArray

on load after invoking service I have set property of selectmenu from variable, but no result?

screenshot Image


problem loading array

Posted: Thu May 30, 2013 1:49 pm
by Kateryna Grynko

Hi Michael,

Probably you use localStorage incorrectly.
localStorage can store strings only. An array is not a string.

You would need to turn the array into the string:
codevar str_array = JSON.stringify( array_variable );
localStorage.setItem( "array_var", str_array );/code
Then to read saved string run the following code:
codevar array_variable = JSON.load( localStorage.getItem( "array_var" ) );/code


problem loading array

Posted: Thu May 30, 2013 2:09 pm
by Michael4771079

Sorry Katya,
im having a bad day,
do you mean run this code with these changes on screen load

codevar str_array = JSON.stringify( array_variable );
localStorage.setItem( "companiesArray", str_array );code

codevar array_variable = JSON.load( localStorage.getItem( "companiesArray" ) );code

/code/code/code/code


problem loading array

Posted: Thu May 30, 2013 6:30 pm
by Maryna Brodina

Working on it...


problem loading array

Posted: Thu May 30, 2013 7:05 pm
by Maryna Brodina

Looks like there is some misunderstanding.
1) Could you clarify what are you going to set in this variable? What is taxiselectmenu? If taxiselectmenu is a selectmenu then most likely you need to set selected item. You can't set selected item from json stringified array. You should do it using JS. Get from array necessary value and with that value set selected item. To help you we need to know what you have in taxiselectmenu and array.
2) If localStorage array forms as result of REST request then in place where you want to set property taxiselectmenu there is no guarantee that array is formed already and saved into localStorage. Do not use the entire code (which works with array) on Load event because REST requests call anisochronous that's why no matter where you place the code in Events list - REST request at this moment can be still not loaded. That's why you need to use array on service success event.


problem loading array

Posted: Thu May 30, 2013 7:42 pm
by Michael4771079

thank Marina your a star!
I have been trying allsorts, got it to work with your help