0
everyone.now.getGuess = function(val) {
  db.view('lists', 'project_names', {
      startkey: val,
      endkey: val + "\u9999"
    }, function(_, data) {
    return data.rows.map(function(obj) {
      return obj['key'];
    });
  });

  return this.now.receiveGuess(guesses[0]);
};

db はnanoのオブジェクトです。db.view は何も返さず、コールバックのみを提供するため、guesess = db.view() は機能しません。そして db.view() のコールバック内では、 now.js にこれにアクセスできませ

どうすればこれを解決できますか?

4

1 に答える 1

3

var self = this;次のパターンを使用できます。

function a() {
    var self = this;
    foo(function(err, data) {
        /* use "self" instead of "this" here */
    });
}
于 2011-11-04T13:36:54.910 に答える