simple-todos.js 707 B

1234567891011121314151617181920212223242526272829
  1. Tasks = new Mongo.Collection("tasks");
  2. if (Meteor.isClient) {
  3. // This code only runs on the client
  4. Template.body.helpers({
  5. tasks: function () {
  6. return Tasks.find({}, { sort: {createdAt: -1 }});
  7. }
  8. });
  9. // Inside the if (Meteor.isClient) block, right after Template.body.helpers:
  10. Template.body.events({
  11. "submit .new-task": function (event) {
  12. // This function is called when the new task form is submitted
  13. var text = event.target.text.value;
  14. Tasks.insert({
  15. text: text,
  16. createdAt: new Date() // current time
  17. });
  18. // Clear form
  19. event.target.text.value = "";
  20. // Prevent default form submit
  21. return false;
  22. }
  23. });}