0
我使用SailsJS创建了一个应用程序。我有一个关于在异步瀑布和异步中使用回调的问题。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)
}
)}
嗨,谢谢你。现在,该值已通过,但未定义。你知道这可能是为什么吗? – steph
你得给我看看那个代码! 我使用像我解释的异步,这就是每个人都这样做。重新审视和调试你的代码,否则发送给我的消息。 – vkstack
您是否将回调(null,yourData)更改为回调(null,item)? – vkstack