0

我正在努力尝试将变量/函数传递给猫鼬查询回调函数。

我想要做的是: 编辑:标题已更改并重新定义示例

Validator.protoptype.customCheck = function(model, path) {

  var self = this // validator object {msg: 'msg', error: ...};

  model.find({name: 'john'}, function(err, res) {
    if (res.length === 0) {
      self.error( self.msg ) // msg hasn't the expected value. 
      // As I have some other validators after this callback gets executed
      // the context is different. don't know how to pass the right context
    } else {
      // something else ...
    }
  }
}
4

0 回答 0