I'm playing around with meteor's Todos example to learn how it works and I'm trying to add a Description to Todo items that appears below the title when you click on it. The "when you click on it" part is what I'm having trouble with. I'm trying to figure out how to add a boolean "viewing" variable to each Todo item client-side without having any reflection of that serverside. Obviously when 1 user is viewing an item not every user would want to view that items. I got a basic implementation going by adding a client-only Collection that was just a list of Todo ids that were being viewed and then used this code for the template to know if a thought was being viewed:
Template.todo_item.viewing = function () {
return Viewing_Todos.find({title: this.title}).count() > 0;
};
This isn't really an ideal solution though. As I said I'd like a client-side boolean variable on each todo item to say whether or not it's being viewed.
I tried changing it to this:
Template.todo_item.viewing = false;
and then my on click event was:
'click .todo-description': function(event) {
event.target.viewing = !event.target.viewing;
}
I added in console log output to see what "event.target.viewing" was and it seemed to be updating correctly but Handlebars was no longer dynamically updating the DOM to reflect that the item was in a "viewing" state.
The Handlebars HTML is:
{{#if viewing}}<br/>
<div class="todo-description">
{{text}}
</div>
{{/if}}
I thought I might have to do it in a helper so I tried the following:
Template.todo_item.helpers({
viewing: false;
});
but that doesn't seem to work at all either.
Thanks for the help! I'm pretty new to web development in general but I'm loving Meteor so far.