gpt4 book ai didi

javascript - Vows with Async 嵌套主题 - 范围问题

转载 作者:行者123 更新时间:2023-11-30 06:02:14 30 4
gpt4 key购买 nike

我希望我的誓言能够从我的主题访问 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);
});
},

关于javascript - Vows with Async 嵌套主题 - 范围问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7563268/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com