Page 1 of 1

Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 7:15 pm
by Bill Clanton

So here is my need. I have a list of photos. I need to add a "like" button to each photo. i want to be able to just simply pass the photo id back to a rest service or create service to add the like for that specific photo to the database.

How can I have it display a like button next to each photo and then only have the id for that specific photo associate with that specific like button.

The key being that this must all function dynamically. It's a photo sharing app similar to an instagram like functionality. Any help is greatly appreciated.


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 7:33 pm
by Kateryna Grynko

Hi Bill,

Add a Grid, in its cells add image, button and hidden label where you will store id.

Here is how to fill values from service: http://docs.appery.io/documentation/r...

To get an appropriate label value on button click run this code:
prevar text = $(this).parents().find("[name=mobilelabelName]").text();/pre


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 7:55 pm
by Bill Clanton

Thank you. this was a huge help. I just had to make one modification to your code. Here is the code from my app that is now working.

var text = $(this).parent().find("[name=photo_id]").text();

Note that i had to change it to be "parent" singular. "parents" gave me every id on the page. So with just that simple mod i was at least at this point able to have it alert me the _id, so now i just need to pass that back to the "like" service that i made. Which i am pretty sure i have a grasp on how to do.

Thank you again.


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 8:09 pm
by Bill Clanton

I just wanted to pass along that i was then able to save the value to a local storage variable and then pass it back to my "like" service mapping request using ...

return {"collName":"Photos","_id": value};

to add it as a pointer to my "likes" collection in the database. I'll be setting up a similar setting to track comments with a specific photo.

Thank you so much for all your help.
everything is working great.


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 8:10 pm
by Kateryna Grynko

Bill,

Let us know if you need any further help.


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 8:19 pm
by Kateryna Grynko

Great it's working as expected :)


Dynamic lists + Buttons + item id's???

Posted: Wed May 07, 2014 9:13 pm
by Bill Clanton

one last thing. perhaps i've just spent to many hours working on this app. But i can't seem to wrap my head around how I could go about having the like button either disappear or change color for photos i've already liked. i have the photo id and user id successfully listed in the likes collection as pointers.

I'm just at a loss as to how I could make it so that if i've liked a photo, the next time I look at the feed the like button would show that i've already liked that photo.

My first thought was to make a query service to have it check each photo as they load to see if i've liked it.

Any ideas would be appreciated.

thanks,


Dynamic lists + Buttons + item id's???

Posted: Thu May 08, 2014 7:00 pm
by Kateryna Grynko

Hi Bill,

Add a field 'like' of boolean type.

Add this JS code on container (Grid) mapping:preif (value.like == "true"){
$(element).find("[name=buttonName]").addClass("liked");
}/pre
Add this CSS for liked photos:pre.liked{
background: red;
}/pre