1234567891011121314151617181920212223242526272829 |
- Tasks = new Mongo.Collection("tasks");
- if (Meteor.isClient) {
- // This code only runs on the client
- Template.body.helpers({
- tasks: function () {
- return Tasks.find({}, { sort: {createdAt: -1 }});
- }
- });
- // Inside the if (Meteor.isClient) block, right after Template.body.helpers:
- 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;
- }
- });}
|