如何在Meteor应用程序中从UI修改数据库
我是meteor的新手,想从用户界面修改数据库文档 我知道我们必须使用但无法使用它,因为我想在单击命令时从UI编辑集合,请建议如何进行 论据 选择器Mongo选择器、对象ID或字符串如何在Meteor应用程序中从UI修改数据库,meteor,Meteor,我是meteor的新手,想从用户界面修改数据库文档 我知道我们必须使用但无法使用它,因为我想在单击命令时从UI编辑集合,请建议如何进行 论据 选择器Mongo选择器、对象ID或字符串 Specifies which documents to modify 修饰符Mongo修饰符 Specifies how to modify the documents 回调函数 **Optional**. If present, called with an error object as the firs
Specifies which documents to modify
修饰符Mongo修饰符
Specifies how to modify the documents
回调函数
**Optional**. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.
请建议如何使用修饰符。让我们用一个事件处理程序来举例说明
Template.example.events({
'click #updateThis':function(e,t){
var newValue = t.$('.newValue').val(); // taking value from random input
Collection.update({_id:this._id},{$set:{value:newValue}},function(error,result){
if(error){
console.log(error.reason)
}else{
console.log("Nice update")
}
})
}
})
因此首先是选择器,就像它说的那样,它应该是要修改的文档的ID
本例中的修饰符是
而回调是为了使它异步,我喜欢使用
error
和result
这两个参数,假设我的表有两个变量:书名和价格,我该怎么做呢?只需改成这个{book:bookName,price:bookPrice}
嘿,Ethaan,它不起作用了:(.我必须使字段可编辑?@garima给我10分钟,我将在MeteorPad上做一个最小的示例这里是@garima