Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

problem with array in localstorage

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.

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

problem with array in localstorage

Hello!

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

problem with array in localstorage

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

problem with array in localstorage

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

problem with array in localstorage

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

problem with array in localstorage

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

problem with array in localstorage

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

Michael4771079
Posts: 0
Joined: Sat Jul 21, 2012 2:03 pm

problem with array in localstorage

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

problem with array in localstorage

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

Return to “Issues”