Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Meteor应用程序中从UI修改数据库_Meteor - Fatal编程技术网

如何在Meteor应用程序中从UI修改数据库

如何在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

我是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 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