async.waterfall(eventIDs.map(function (eventId) {
console.log(eventId);
return function (lastItemResult, nextCallback) {
if (!nextCallback) {
nextCallback = lastItemResult;
lastItemResult = null;
}
// same execution for each item in the array
var eventPromise = loadEventsData.loadFormData(eventId, apiList);
eventPromise.then(function (response) {
console.log(response);
var itemResult = response;
// results carried along from each to the next
nextCallback(itemResult, nextCallback);
});
}}), function (err, result) {
// final callback
});
console.log(eventId)
的输出是正确的,它的打印次数与数组中各项的次数相同。但是console.log(response)
仅打印一次,这意味着回调没有被正确调用? 最佳答案
我进行了修改,问题已解决
nextCallback(null, itemResult);