簡體   English   中英

具有異步嵌套主題的誓言-范圍問題

[英]Vows with Async nested topics - scope problem

我希望我的誓言可以從我的主題訪問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);
  });
},

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM