开发者

Vows with Async nested topics - scope problem

开发者 https://www.devze.com 2023-04-08 09:31 出处:网络
I want my vow to have access to outerDocs and innerDocs from my topics but it doesn\'t. \'ASYNC TOPIC\': {

I want my vow to have access to outerDocs and innerDocs from my topics but it doesn't.

'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) {开发者_Python百科
      console.log(err, innerDocs, outerDocs);
      return assert.equal(1, 1);
    }
  }

What am I doing wrong?


You can't set arguments to the callback like that, the find function will do that itself. Do this instead:

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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号