Skip to content

Instantly share code, notes, and snippets.

@shu0115
Created November 14, 2014 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shu0115/6d943b19878ccb7d63a3 to your computer and use it in GitHub Desktop.
Save shu0115/6d943b19878ccb7d63a3 to your computer and use it in GitHub Desktop.
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;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment