I am retrieving values from collection and display in a div section using a for each loop, basically its a div that has the button in it, I want to get the value from a div section. Please check the attached screenshot.
When I try to get the values from the **post_id**, I am getting the same values every time, I donāt know how to get different values from different divs, Please help me, I am getting stuck at this
what i do is use a separate template for the listās elements so the data getās encapsulated in a clean way and is easily accessible without writing it into the template
// list.js
Template.someList.helpers({
"elements": function () {
// provide the elements
return ["aaa","bbb","ccc","ddd"];
}
});
// someList.html
<template name="someList">
{{#each element in elements}}
{{!-- hand over the element as 'data' to the other template --}}
{{> listElement data=element}}
{{/each}}
</template>
// listElement.js
Template.listElement.events({
"click .js-like": function (e) {
console.dir(this); // will print data
}
});
// listElement.html
<template name="listElement">
{{!-- your post here. you can directly print from the passed parameter --}}
{{ data }}
<button class="js-like">like</button> {{!-- nothing else needed. i like to prepend js- to classes with handlers so i know which are for styling and which are for logic --}}
</template>
Well, I am new to the frontend, I belong to mobile app community. It takes time to understood what you are has said, but your solution was wrong, there should be class instead of Id, this is the main logic I would say. Thanks for the help.
By the way I am stuck at cropping image, can you help me in this