Page 3 of 3

How to add an item to "Favourites" locally in the device, not in the server?

Posted: Fri Jan 24, 2014 5:22 pm
by Alex GG

Hello Katya,
No errors...in console...If you just guide me on how to correctly use the above code (to delete items from the ARRAY)...I have tried different ways with no luck...
Thanks =)


How to add an item to "Favourites" locally in the device, not in the server?

Posted: Fri Jan 24, 2014 7:47 pm
by Maryna Brodina

Hello! Could you clarify what do you send in itemValue? For example to delete first value from screen what would you send "a" or "52d9a36..."?


How to add an item to "Favourites" locally in the device, not in the server?

Posted: Fri Jan 24, 2014 9:28 pm
by Alex GG

hello Maryna,
I have tried with both:
removeArrayItem('favorites',Appery('negocioo').text());
removeArrayItem('favorites',Appery('idd').text());
but none does anything...no one item is delete from the array...


How to add an item to "Favourites" locally in the device, not in the server?

Posted: Fri Jan 24, 2014 10:09 pm
by Maryna Brodina

Let's say you delete with nombre_negocio value. Replace your functions to the following prefunction myload(varName) {
var arr;
try {
arr = JSON.parse(localStorage.getItem(varName));
if ({}.toString.call(arr) !== "[object Array]") {
arr = [];
}
} catch ( e ) {
arr = [];
}
return arr;
}

function save(item, varName) {
var arr = myload(varName);
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr));
}

function removeArrayItem(varName, itemValue) {
var arr = myload(varName), i, len;
for (i = 0, len = arr&#46;length; i < len; i++) {
if (arr['nombre_negocio'] === itemValue) {
arr&#46;splice(i, 1);
break;
}
}
localStorage&#46;setItem(varName, JSON&#46;stringify(arr));
}/pre


How to add an item to "Favourites" locally in the device, not in the server?

Posted: Fri Jan 24, 2014 10:40 pm
by Alex GG

Thanks Maryna, it works fine!!!
I just need to work on swaping both icons at button click, in order to avoid user add to favorites the same item several times...If I have trouble hope you could help!
=)