尝试从流星官方教程中的待办事项列表上创建编辑功能

时间:2015-01-16 03:45:40

标签: meteor

我目前正在尝试为流星官方教程上的待办事项列表创建一个编辑按钮。我是流星的新手所以你能帮忙吗?

HTML代码:

<head>
  <title>Todo List</title>
</head>

<body>
  <div class="container">
    <header>
      <h1>Todo List</h1>

      <form class="new-task">
        <input type="text" name="text" placeholder="Type to add new tasks" />
      </form>
    </header>

    <ul>
      {{#each tasks}}
        {{> task}}
      {{/each}}
    </ul>
  </div>
</body>

<template name="task">
  <li class="{{#if checked}}checked{{/if}}">
    <button class="delete">&times;</button>
    <!-- Adding the edit button -->
    <button class="edit">Edit</button>

    <input type="checkbox" checked="{{checked}}" class="toggle-checked" />

    <span class="text">{{text}}</span>
  </li>
</template>

我的App.js代码:

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);
    },
    //trying to figure out how to add the edit function here
    "click .edit": function () {
      Tasks.update(this._id, {});
    }
  });
}

我在互联网上看都无济于事,所以我转向了我的最后一招,即stackoverflow。无论是退伍军人还是在这个流星领域都有经验的人,我都会非常感激!

0 个答案:

没有答案