Reputation: 536
I am trying to access the individual document within a #each in Meteor so that I can mark it. Basically if the user clicks on the content I want to run some logic on that document. Example:
{{#each document}}
<div>
{{text}}
{{did_i_read_the_doc}}
</div>
{{/each}}
and I want the {{did_i_read_the_doc}} to show "yes" or "no" depending on whether it is marked in the collection. So in my template helper I want something like
Template.documents.helpers({
did_i_read_the_doc: function() {
//what goes here?
if (thisIndividualDocument.contains(Meteor.userId() in "readBy")
show "yes" in html
else
show "no" in html
}
I'm not sure how to access the individual mongo document in the helpers wrapped in an each block. I'm used to the logic of returning all of the documents in a helper documents: function() { return Documents.find({}) }
but how would I define a helper function that gets the individual document? In the final run of things I want to be able to click a document and mark it as read, like a notification, and have something that shows up saying "already read" or "unread" depending.
Upvotes: 0
Views: 57
Reputation: 536
I figured this out right after I posted.
In the helper method you can use
my: function() {
if(this.field)
//do something
so 'this' grabs the individual document.
EDIT: just for example to solve my specific case
did_i_read_the_doc: function() {
if(this.read) {
return "yes"
}
else {
return "no"
}
}
Upvotes: 1