Page 1 of 3

spliting an array

Posted: Wed Oct 30, 2013 12:02 pm
by Michael4771079

Hi,

I am trying to complete the ordering process of an app for a fastfood store.

this is wrer I am now.

The end user can login, and order from menu, order is saved in an array in localstorage,

user clicks "checkout" array is sent to user db (with this js in mapping
"return JSON.parse(value);)"
and app navs to checkout screen,

on checkout load the array is called and as you can see from the attached image, it is mapped to a label, no js in mapping

the ui under the array is what I am trying to get to. The collapsible is in a grid and I would like to to populate the labels with the content of the array.

My reason for this logic is that I cannot tell how many items a user may order, so I cannot build a ui

I understand I need to split the array,
does the array need to be split before it reaches the db (in mapping) for example,

or can the array be manipulated during the "get" service call?

screenshot in tester
Image

in builder
Image

cheers


spliting an array

Posted: Wed Oct 30, 2013 2:27 pm
by Kateryna Grynko

Hi Michael,

Please take a look at here: https://developer.mozilla.org/en-US/d...


spliting an array

Posted: Wed Oct 30, 2013 3:10 pm
by Michael4771079

Thanks Katya,
so in order to be able to map the contents of localstorage array I need to split the array on ,
Can I assume I do this after saving to localstorage and before the put service to the db

"[{"Pizza":"Margarita","Size":"Fourteen Inch Stuffed Crust","Base":"off","Price":"8.00"}]"

and if so I assume I will need to change this js
"return JSON.parse(value);)"


spliting an array

Posted: Wed Oct 30, 2013 8:53 pm
by Michael4771079

OK folks,
I am getting nowhere with this issue, so if possible can we do this.

Can someone tell me the steps I need to take to be able to map the array in my local storage, from the db to the labels, in a collapsibleblock, in a grid

the array has been"put" in the db with this js. return JSON.parse(value);

so this wont work,
do I need to convert or split the array saved in localstorage before I send it to the db.
can you tell me what I am converting or splitting and what do I need to convert it to?
I need to know these steps required so as I can get some outside help with this issue

regards


spliting an array

Posted: Thu Oct 31, 2013 12:09 am
by Michael4771079

Igor,
can you help me here?


spliting an array

Posted: Thu Oct 31, 2013 12:32 am
by Igor

Yes. I'm looking on your App now.


spliting an array

Posted: Thu Oct 31, 2013 2:35 am
by Igor

You can use next code to parse JSON from local storage:
precode
var o = JSON.parse(localStorage.getItem("variableName"));
for (var i=0;i<o&#46;length;i++)
{
alert("SIZE: "+o&#46;Size+"Price: "+o&#46;Price+"Pizza: "+o&#46;Pizza+"Base: "+o&#46;Base);

}/code/pre

Using for statement, you need to put objects to some component, for example try to put objects to separate labels.


spliting an array

Posted: Thu Oct 31, 2013 10:03 pm
by Michael4771079

Hi Igor,
inserted code but I am getting error on click checkout btn.
Here are some s/s

Image

Image

Image

cheers


spliting an array

Posted: Fri Nov 01, 2013 9:12 am
by Kateryna Grynko

Hi Michael,

What do you store in localStogage variable 'variableName'?
You should change localStorage.getItem("variableName") to value.


spliting an array

Posted: Fri Nov 01, 2013 11:51 am
by Michael4771079

Cheers Katya,
I had tried that but the error still remains the same as above