且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在 MongoDB 更新语句中使用变量

更新时间:2022-12-27 20:31:33

你可以这样做:

'blur .editable' : function () {
  var target = event.currentTarget.value;
  var field = event.currentTarget.name;

  var obj = {};
      obj[field] = target;
  Hostings.update( { _id: this._id },{ $set: obj } );
}

Javascrip 对象可以通过两种方式访问​​:

Javascrip objects can be accessed two ways:

object.attribute

object["attribute"]

如果你使用第二种方法,你可以用一个变量来访问它

if you use the second method you can access it with a variable