我正在用 SailsJS 创建一个应用程序。我有一个关于在异步瀑布和异步中使用回调的问题。
我在异步瀑布函数中有两个函数。第一个回调返回正确的值。第二个函数有一个嵌套回调。但是,嵌套回调的值卡在水线查找函数中,并且永远不会返回到外部函数。
你知道我如何将值返回给外部函数吗?
谢谢你的帮助。
myFunction: function (req,res) {
async.waterfall([
function(callback){
// native MongoDB search function that returns an Array of Objects
},
function(result, callback){
async.each(resultAll, function (location){
Model.find({location:'56d1653a34de610115d48aea'}).populate('location')
.exec(function(err, item, cb){
console.log (item) // returns the correct value, but the value cant be passed to the outer function
})
})
callback(null, result);
}], function (err, result) {
// result is 'd'
res.send (result)
}
)}