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 不返回任何内容,只提供回调,因此guesses = 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 回答