Created
November 14, 2014 04:27
-
-
Save shu0115/9e19215ce4460eda331f to your computer and use it in GitHub Desktop.
This file contains 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
Tasks = new Mongo.Collection("tasks"); | |
if (Meteor.isClient) { | |
// This code only runs on the client | |
Template.body.helpers({ | |
tasks: function () { | |
// Show newest tasks first | |
return Tasks.find({}, {sort: {createdAt: -1}}); | |
} | |
}); | |
Template.body.events({ | |
"submit .new-task": function (event) { | |
// This function is called when the new task form is submitted | |
var text = event.target.text.value; | |
Tasks.insert({ | |
text: text, | |
createdAt: new Date() // current time | |
}); | |
// Clear form | |
event.target.text.value = ""; | |
// Prevent default form submit | |
return false; | |
} | |
}); | |
Template.task.events({ | |
"click .toggle-checked": function () { | |
// Set the checked property to the opposite of its current value | |
Tasks.update(this._id, {$set: {checked: ! this.checked}}); | |
}, | |
"click .delete": function () { | |
Tasks.remove(this._id); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment