我對異步瀑布有點問題,因爲我想在循環處理的函數之後調用下一個函數。腳本是異步瀑布流的一部分,以前的函數工作得很好。這裏唯一的事情是,它有一個用於loop.The代碼below.Any幫助將是非常appreciated.Thanks節點js異步回調問題
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)
},
你的回撥在哪裏?它是瀑布代碼的一半,你可以發佈你的async.waterfall代碼嗎? – abdulbarik
@abdulbarik我編輯了代碼。我的回調是下一個功能,它採取行,並簡單地打印它 –
什麼是控制檯打印'console.log(「行是:」+行)'? – abdulbarik