我希望我的誓言可以从我的主题访问outerDocs和innerDocs,但事实并非如此。

'ASYNC TOPIC': {
  topic: function() {
    aModel.find({}, this.callback);
  },
  'NESTED ASYNC TOPIC': {
    topic: function(outerDocs) {
      anotherModel.find({}, this.callback(null, innerDocs, outerDocs));
    },
    'SHOULD HAVE ACCESS TO BOTH SETS OF DOCS': function(err, innerDocs, outerDocs) {
      console.log(err, innerDocs, outerDocs);
      return assert.equal(1, 1);
    }
  }


我究竟做错了什么?

最佳答案

您不能像这样为回调设置参数,find函数将自己完成。改为这样做:

topic: function(outerDocs) {
  var self = this;
  anotherModel.find({}, function(err, docs) {
    self.callback(err, docs, outerDocs);
  });
},

10-06 15:30