Page 4 of 8

how to calculate label values in an array

Posted: Wed Nov 20, 2013 7:43 pm
by Kateryna Grynko

Michael,

We advice you the check of array length needed to escape this situation.
Please return it.


how to calculate label values in an array

Posted: Wed Nov 20, 2013 8:30 pm
by Michael4771079

Katya,
im getting more and more confused here.

Maryna mentioned that if arrays are not the same size some of the code provided would need to be deleted.

So as not to confuse myself more I I have the Maryna's code in s/s underlined what Maryna mentioned.

I have added and ran this code and the result was no errors, but you can see the result in local storage, no result.

Can you please tell me how to edit Maryna's code so I can make this headache go away

Image

Image


how to calculate label values in an array

Posted: Wed Nov 20, 2013 8:37 pm
by Michael4771079

sorry wrong localstorage image, this is the one

Image


how to calculate label values in an array

Posted: Wed Nov 20, 2013 8:38 pm
by Michael4771079

wrong localstorage image, this is the one

Image


how to calculate label values in an array

Posted: Thu Nov 21, 2013 8:59 am
by Maryna Brodina

Hello! Sorry, there seems to be some misunderstanding. Could you clarify please? You don't need to get new array and sum each element from this array with corresponding element from another array? You just need to summarize total Price from two arrays, correct?


how to calculate label values in an array

Posted: Thu Nov 21, 2013 10:15 am
by Michael4771079

Correct Maryna,
I just need to show the total price for the order from the 2 arrays on the screen.

thx


how to calculate label values in an array

Posted: Thu Nov 21, 2013 2:00 pm
by Maryna Brodina

Please try this code:
prevar price;
try {
price = JSON.parse(localStorage.getItem("mainorderArray"));
if ({}.toString.call(price) !== "[object Array]") {
price = [];
}
} catch ( e ) {
price = [];
}
var extrasprice;
try {
extrasprice = JSON.parse(localStorage.getItem("livesundriesorderArray"));
if ({}.toString.call(extrasprice) !== "[object Array]") {
extrasprice = [];
}
} catch ( e ) {
extrasprice = [];
}
var totalprice = 0;
for (i = 0; i < price&#46;length; i++){
totalprice += +price["Price"]
};
for (i = 0; i < extrasprice&#46;length; i++){
totalprice += +extrasprice["Price"];
};
localStorage&#46;setItem("totalprice", totalprice);/pre


how to calculate label values in an array

Posted: Fri Nov 22, 2013 10:54 am
by Michael4771079

Thanks Maryna,
all working, when tested in apperyio tester. But not on the device.

Heres whats happening

I nav to sundries page and select some items and click to order them,
next I click checkout, on page load STARUSERREAD service is called and all products ordered are on the page.
All good so far
I click to delete an item, the code to delete is run, followed by this code to refresh the page, in tester it works perfectly everytime

$.mobile.changePage("checkout.html", { allowSamePageTransition: true,
transition: "flip", reloadPage: true });

as apk and on iphone using qr code in mobile preview

when the page refreshes sometimes it works and the item is deleted, the page refreshes and returns the remaining items in the arrays and sometimes it refreshes and returns nothing at all, even though there are items in the db.

So is the code I have used to refresh correct?


how to calculate label values in an array

Posted: Fri Nov 22, 2013 12:05 pm
by Maryna Brodina

Hello! Code is correct, perhaps there are some problems with app logic. Please try to test. You have to clear localStorage in browser:
prelocalStorage&#46;clear();/preFor example add this code on button click on Start screen, install app on device, repeat steps which caused error.
Run test in browser, clear localStorage, repeat the same steps. Is there the same error?
If it's still the same you would need to change app logic. If error not reproducible in browser, but still reproducible on device - let us know and post steps so we can reproduce it on our end.


how to calculate label values in an array

Posted: Fri Nov 22, 2013 1:38 pm
by Michael4771079

Hi Maryna,
Im getting a range of different results.

for example,
I click delete to delete item on checkout page, the delete code runs, I can see the item being removed from localstorage,

the next event is staruserupdate "put" but this not firing
there is an error "SyntaxError JSON.parse: unexpected end of data" in console, you can also see that the put service is not firing all of the time when delete button is clicked

Image

Image