Michael,
We advice you the check of array length needed to escape this situation.
Please return it.
Michael,
We advice you the check of array length needed to escape this situation.
Please return it.
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
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?
Correct Maryna,
I just need to show the total price for the order from the 2 arrays on the screen.
thx
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.length; i++){
totalprice += +price["Price"]
};
for (i = 0; i < extrasprice.length; i++){
totalprice += +extrasprice["Price"];
};
localStorage.setItem("totalprice", totalprice);/pre
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?
Hello! Code is correct, perhaps there are some problems with app logic. Please try to test. You have to clear localStorage in browser:
prelocalStorage.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.
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