Mongodb 尝试使用Meteor JS将编辑功能添加到待办事项列表程序中?
我是流星JS的新手,我一直在关注他们网站上的官方教程。 我想在原来的完成和删除按钮中添加一个编辑按钮会很好。 我似乎不知道如何添加编辑todo项的功能。我已经通过html添加了编辑按钮本身,但我只需要弄清楚如何添加实际编辑项目本身的功能 以下是javascript代码:Mongodb 尝试使用Meteor JS将编辑功能添加到待办事项列表程序中?,mongodb,meteor,Mongodb,Meteor,我是流星JS的新手,我一直在关注他们网站上的官方教程。 我想在原来的完成和删除按钮中添加一个编辑按钮会很好。 我似乎不知道如何添加编辑todo项的功能。我已经通过html添加了编辑按钮本身,但我只需要弄清楚如何添加实际编辑项目本身的功能 以下是javascript代码: Tasks = new Mongo.Collection("tasks"); if (Meteor.isClient) { // This code only runs on the client Template.b
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);
},
"click .edit": function () {
Tasks.update(this._id, {});
}
});
}
非常感谢您的帮助 我认为您在使用它时遗漏了一些内容,而Todo的官方示例具有Todo的编辑功能。它只是对每个todo项进行内联编辑。他在谈论教程:完整的todo示例的方式是始终在
输入
元素中显示todo项文本,该元素的样式类似于纯文本,然后捕获键下
和键上
事件以保存任何更改。