Skip to content

Instantly share code, notes, and snippets.

@panw
Created August 1, 2014 05:23
Show Gist options
  • Save panw/6b367bd90d67c8e7c967 to your computer and use it in GitHub Desktop.
Save panw/6b367bd90d67c8e7c967 to your computer and use it in GitHub Desktop.
For part 4 of the tutorial. Updated code so users could check off items from the list.
Items = new Meteor.Collection('items');
if(Meteor.isClient){
Template.groceryList.events({
'click li' : function(event, template){
var listItem = event.currentTarget; // get the list item being clicked on
$('#'+listItem.id).hide(); // hide li with matching id
// update check attribute for the item in the database
Items.update(listItem.id, { $set : {checked:true} }, function(error){
// if error occurs print it out
if(error){
console.log(error.reason);
}
});
}
});
Template.groceryList.helpers({
items: function() {
return Items.find({checked:false});
}
});
}
if(Meteor.isServer){
if (Items.find().count() === 0) {
Items.insert({ name: "Baguette", checked: false });
Items.insert({ name: "Butter", checked: false });
Items.insert({ name: "Jam", checked: false });
Items.insert({ name: "Coconut", checked: false });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment