如果单击更新,Meteor显示更新字段而不是项目

如果单击更新,Meteor显示更新字段而不是项目,meteor,Meteor,我有一个最简单的流星计划,但我被一些基本的东西卡住了。我有一个表单字段,当我输入一个项目时,它进入Mongo集合。我检索并显示该集合,以及要删除或编辑的按钮。我想做的是单击edit,然后该项变成一个文本框(预先填充原始值),您可以更改、单击return并更新该项。我被困在如何正确传递_id和/或如何仅将正确的条目转换为字段中 My.html文件: <head> <title>Memorial</title> </head> <body&

我有一个最简单的流星计划,但我被一些基本的东西卡住了。我有一个表单字段,当我输入一个项目时,它进入Mongo集合。我检索并显示该集合,以及要删除或编辑的按钮。我想做的是单击edit,然后该项变成一个文本框(预先填充原始值),您可以更改、单击return并更新该项。我被困在如何正确传递_id和/或如何仅将正确的条目转换为字段中

My.html文件:

<head>
  <title>Memorial</title>
</head>

<body>
  <h1>Memorial Testing!</h1>

<form class="new-task">
    <input type="text" name="text" placehoder="Type stuff here" />
</form>
    {{> listing}}
</body>


<template name="listing">
    <ul>
        {{#each tasks}}
            {{> crudlist}}
        {{/each}}
    </ul>
</template>

<template name="crudlist">
    {{#if editor}}
        {{#if editid == this._id}}
            <li><input type="text" name="text" placehoder="Type stuff here" value="{{text}}"/></li>
        {{else}}
            <li>{{text}} :: <button name="delete" class="delete">Delete</button><button name="edit" class="edit">Edit</button></li>
        {{/if}}
    {{/if}}
</template>

感谢您的帮助。

要获取刚才单击的内容,您应该使用文档中的event.target

}))

Tasks = new Mongo.Collection("tasks");

if (Meteor.isClient) {

  Template.listing.helpers({
    tasks: function() {
      return Tasks.find({});
    }
  });

  Template.crudlist.helpers({
    editor: function() {
      return Session.get("editor");
    },
    editid: function() {
      return Session.get("editid");
    }
  });


  Template.body.events({
    "submit .new-task": function (event) {
      var text = event.target.text.value;

      Tasks.insert({
        text: text,
        createdAt: new Date()
      });
      event.target.text.value = "";
      return false;
    }
  });


  Template.crudlist.events({
    "click .delete": function () {
      Tasks.remove(this._id);
    },
    "click .edit": function () {
      Session.set("editor","true");
      Session.set("editid",this._id);
    }
  });
}


if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}
Template.crudlist.events({
    "click .delete": function (event,template) {
      var whatYouJustClicked = event.target,
          targetID = $(whatYouJustClicked).attr('id')
    },
    "click .edit": function (event,template) {
      var whatYouJustClicked = event.target,
          targetID = $(whatYouJustClicked).attr('id')
      Session.set("editor","true");
      Session.set("editid",targetID);
    }