Page 1 of 3

problem with array in localstorage

Posted: Mon Oct 21, 2013 9:36 pm
by Michael4771079

Hi,
I am trying to get an array to localstorage but I have a prob.

I have the item id from the collection in localstorage.
I used this id for a get service, and it works in test, here is a screenshot

Image

this is the request and response mapping

Image Image

I used this js in response mapping, (This I got from a previous array to localstorage service), mabe the code is wrong?

Image

and this is the result in the firefox

Image

it appears to be trying to load, but just not there yet.
Any help will be appreciated.


problem with array in localstorage

Posted: Mon Oct 21, 2013 10:41 pm
by Alena Prykhodko

Hello!

We'll test and update, but it can take some time.


problem with array in localstorage

Posted: Mon Oct 21, 2013 11:05 pm
by Michael4771079

Thanks alot Alena,
app name star pizza and its been shared with apperyio support.

I made a change that had some effect.
I changed this

Image

to this

Image

the localstorage in the dom now shows this, all the sizes but no prices? But the prices are in the array in the collection, (last screenshot) Image
Image

thanks for the help, its driving me mad


problem with array in localstorage

Posted: Mon Oct 21, 2013 11:32 pm
by Michael4771079

Hi,
just to let you know, I deleted the js in the mapping, and now the array is showing size and price in localstorage, haowever its only showing the values for the first pizza "margarita" it doesnt change when you click on any of the other selectmenus

cheers


problem with array in localstorage

Posted: Mon Oct 21, 2013 11:33 pm
by Michael4771079

problem with array in localstorage

Posted: Tue Oct 22, 2013 12:20 am
by Alena Prykhodko

Please read this post https://getsatisfaction.com/apperyio/... and let us know about result.


problem with array in localstorage

Posted: Tue Oct 22, 2013 12:40 am
by Michael4771079

Sorry Alena,
I don't think I explained correctly,
I know I will need to populate the selectmenu,

but first I need to find out why, when the array is called with a virtual click on a selectmenu it returns the same label and value to localstorage, no matter which of the 5 selectmenus are clicked on the screen, the rest service is requested with the item id in the collection

thanks


problem with array in localstorage

Posted: Tue Oct 22, 2013 10:39 am
by Maryna Brodina

Hello! It's better to fill in Select directly (without saving to localStorage). To do that:
1) star_test_read_service response should look like this
Image
2) Delete event chickenpizzaselectmenu-Virtual click-Invoke service-sizepricearray
3) In service readtest_collection do the following mapping
Image
4) In mapping add JS:
prefunction strRepresentationToObject(str) {
str = str.slice(1, -1);
var i, len, obj={}, tmp, arr = str.split(', ');
for (i = 0, len = arr&#46;length; i < len; i++) {
tmp = arr&#46;split('=');
obj[tmp[0]] = tmp[1];
}
return obj;
}
var valuesArray;
try {
valuesArray = JSON&#46;parse(value);
if ({}&#46;toString&#46;call(valuesArray) !== "[object Array]") {
valuesArray = [];
}
} catch ( e ) {
valuesArray = [];
}
var i, len, obj, $element = $(element);
$element&#46;empty();
for (var i = 0, len = value&#46;length; i < len; i++) {
obj =strRepresentationToObject(value);
$element&#46;append('<option rerender="chickenpizzaselectmenu" value="' + obj['price'] + '">' + obj['size'] + '<&#47;option>');
}
return true;/pre


problem with array in localstorage

Posted: Tue Oct 22, 2013 11:39 am
by Michael4771079

Hi Marina,
I done what you said but no result on selectmenu, no errors in console, here are my screenshots, service is invoked on page load

Image

Image

Image

Image


problem with array in localstorage

Posted: Tue Oct 22, 2013 12:06 pm
by Maryna Brodina

Sorry, the code hasn't been posted correctly. I updated the code. Please try again.