【发布时间】:2015-10-16 23:44:29
【问题描述】:
我不是 node 和 async.js 方面的专家。所以期待 node js 社区的帮助。所以这是我的场景,我想一个接一个地做 3 次操作,每个都取决于以前的结果。通过使用以前的结果,我需要调用异步函数来检索另一个结果。所以我决定使用异步瀑布。 (希望我选择了正确的一个)。
async.waterfall([
function(callback) {
request({
method: 'GET',
headers: {'Content-Type' : 'application/json'},
url : url
},function(error, response, body){
if(error) {
callback(error);
} else {
var result= JSON.parse(body);
callback(null,result); //sending to next function
}
});
},
function(result, callback) {
//here i want to use the result array in loop async.eachSeries or forEachSeries and fetch another result array using request module then send it to next function
/*Here I don't know How to process the result*/
callback(null,result1)
},
function(result1, callback) {
//here i want to use the result1 array and fetch another result array then send it to next function
callback(null,result2)
}
], function(error, res) {
console.log(res); // process final result
});
我参考了一些教程。我无法理解这就是为什么最终会在这里。提前致谢。
【问题讨论】:
-
我想帮你但我真的不明白你的问题是什么
-
嗨,我第一步成功了,(将结果发送到第二个函数)。我真的不知道如何在第二步中使用循环和回调进行处理
-
我现在正在回复,请尝试编辑您自己的问题,更明确地说明您的问题
标签: javascript node.js async.js