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