Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi Kateryna,

This worked, thank you.

instead of mapping to a toggle i mapped to 'visible' of 2 separate buttons that show or hide based on the code you gave me.

Image

Image

At the moment when the list of all the items renders it checks the _id of each item during mapping to find if it's in the 'Source_Id' in the Favourite local storage, if yes, then button Fav_ON is visible.
I need to take this a step further but don't know the code for it.
If yes, I want the 'FavCollection_Id' from Favourite local storage to be mapped/binded to a label on the list item.

How would i write this?

Thank you,
Joe

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

user favourite items

Hello!

I am sorry for delay!

On this condition add the following code preelement.parent().find("[name=labelName]").text(lsData);/prewhere labelName - label name

Joe Sharples
Posts: 0
Joined: Mon Aug 18, 2014 1:31 pm

user favourite items

Hi Maryna,

how exactly do I add this to my existing code?

on the mapping from _id to Fav_ON button i have the JS:

pre
var lsData = Appery.storage.Favourite.get();
if ( _.findWhere( lsData, { Source_Id: value } ) ) {
return true;
}
return false;
/pre

where Fav_ON is the button that informs users that the item is in their favourite collection.
I also have the same code, with the true and false swapped round, mapped to another button, Fav_OFF, which informs users that the item is not in their favourites collection.

The 'Favourite' model has 3 items, Name, Source_Id and FavCollection_Id.
I also have a 'FavouriteArray' model, where the 'FavouriteArray' type is the 'Favourite' model above. The 'favourite' collection is mapped to this.

I want each item, if pre( _.findWhere( lsData, { Source_Id: value } ) )/pre then the Fav_ON button show and the 'FavCollection_Id' for that item to be mapped to a label on the list item. This way all the items in the list that are also in the 'Favourite' collection will have the _id for the 'favourite' collection (FavCollection_Id) listed too.

The reason for me wanting to do this is it will then allow me to create a delete service that maps this label to _id of the 'favourite' collection.

Does my explanation make sense?
how would i add your code to my existing code to achieve this?

Thank you,
Joe

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

user favourite items

Hello Joe,

I.e. in the code, that is running in the mapping to Fav_ON in the branch, in which the condition is true (i.e., "yes" as it was mentioned), you should complete also this code before return true;
preelement.parent().find("[name=labelName]").text(lsData);/pre
name must match the name of the label in which lsData will be displayed.

Sunita
Posts: 0
Joined: Sat Nov 15, 2014 2:40 pm

user favourite items

Hi Joe, how did you save the item name and id to local storage?

Can you please explain in details how did you manage to get this whole thing working? It will be of great help to me

Return to “Issues”