Vows with Async nested topics - scope problem
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);
});
},
精彩评论