Created
August 1, 2014 05:23
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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