我有一点问题与异步瀑布,因为我想调用下一个函数后,其中循环正在处理的函数。该脚本是异步瀑布流的一部分,以前的功能工作得很好。唯一的区别就是它有一个for循环。代码如下。任何帮助都将非常感激。由于
function(querySize,req)
{
console.log("in second function call :" +querySize);
var temp,title;
for(var counter = 0;counter <= querySize;counter++)
{
websiteAddressArray[counter] = req.query.address[counter];
console.log("for is : " +req.query.address[counter]);
console.log("first line is : " +websiteAddressArray[counter]);
console.log("second line is : " +websiteAddressArray[counter]);
request(websiteAddressArray[counter], function(err, resp, body)
{
$ = cheerio.load(body);
console.log("title is : " +$('title').text());
titleArray[counter] = $('title').text();
});
}
var line="this is string";
callback(null,line);
},
function(callback,line)
{
console.log("line is : " +line)
},
您的syntax
不正确。总是在async中传递callback
最后一个参数。瀑布
function(querySize, req,callback) {
console.log("in second function call :" + querySize);
var temp, title;
for (var counter = 0; counter <= querySize; counter++) {
websiteAddressArray[counter] = req.query.address[counter];
console.log("for is : " + req.query.address[counter]);
console.log("first line is : " + websiteAddressArray[counter]);
console.log("second line is : " + websiteAddressArray[counter]);
request(websiteAddressArray[counter], function(err, resp, body) {
$ = cheerio.load(body);
console.log("title is : " + $('title').text());
titleArray[counter] = $('title').text();
});
}
var line = "this is string";
callback(null, line);
},
function(callback, line) {
console.log("line is : " + line)
},