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

spliting an array

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

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

spliting an array

Hi Michael,

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

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

spliting an array

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);)"

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

spliting an array

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

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

spliting an array

Igor,
can you help me here?

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

spliting an array

Yes. I'm looking on your App now.

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

spliting an array

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.

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

spliting an array

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

Image

Image

Image

cheers

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

spliting an array

Hi Michael,

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

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

spliting an array

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

Return to “Issues”