Hello Appery team!
I ́m also have an "add/remove from Favorites" functionallity in may app...I have follow this post and I ́m able to add items to the favorits list. And then, using Generic Service, to retrieve the items to another list.
this is what I want to do:
In order to avoid user add same item multiple times in the favorite list I want to dinamically change the icon using this:
Appery('Image_favorits').attr('src', Appery.getImagePath('addfavorits.jpg'));
or if this is the case,
Appery('Image_favorits').attr('src', Appery.getImagePath('removefavorits.jpg'));
so, if the user decides to remove from favorits list, he just click "X"...
I also look at this past post to remove items from an Array:
https://getsatisfaction.com/apperyio/...
using this on button click:
removeArrayItem('favorites',Appery('negocioo').text());
and adding this custom JS:
function save(item, varName) {
var arr = localStorage.getItem(varName);
if(arr == null) {
arr = new Array();
}
else {
arr = JSON.parse(arr);
}
arr.push(item);
localStorage.setItem(varName, JSON.stringify(arr));
}
function myload(varName) {
var arr = localStorage.getItem(varName);
if(arr == null) {
arr = new Array();
}
else {
arr = JSON.parse(arr);
}
return arr;
}
function removeArrayItem(varName, itemValue) {
var arr = myload(varName);
if(arr.indexOf(itemValue) != -1) {
arr.splice(arr.indexOf(itemvalue));
localStorage.setItem(varName, JSON.stringify(arr));
}
}
But I ́m not able to remove any item..I ́m lost...Could you point me on how to do the trick???
BTW this is what I have in "favorits" local Variable:
Regards