2
我有一個名爲recipesArray的對象數組數組。突破javascript嵌套的async.each循環,但繼續主循環
recipesArray = [ [{name = "the recipe name", url = "http://recipeurl.com"},
{name = "the other neame", url = "http://adifferenturl.com"},
{name = "another recipe", url = "http://anotherurl.com"}],
[{name = "the recipe name", url = "http://recipeurl.com"},
{name = "the other neame", url = "http://adifferenturl.com"},
{name = "another recipe", url = "http://anotherurl.com"}],
[{name = "the recipe name", url = "http://recipeurl.com"},
{name = "the other neame", url = "http://adifferenturl.com"},
{name = "another recipe", url = "http://anotherurl.com"}] ]
我想擺脫這個嵌套的async.each循環,但繼續主async.each循環。
// main async.each
async.each(recipes, function(subArray, callback1) {
// nested async.each
async.each(subArray, function(theCurrentRecipe, callback2) {
checkHREFS(theCurrentRecipe, function(thisRecipe) {
if ('i have a conditional here') {
// break out of this nested async.each,
// but continue the main async.each.
} else {
// continue
}
callback2();
});
}, callback1);
}, function(err) {
if (err) {
return console.error(err);
// success, all recipes iterated
});
這似乎是它的工作,感謝@mscdex。 – Joel
雖然我仍然想知道是否有更好的辦法比僞造一個錯誤。 – Joel
當前沒有使用'async'模塊,當我需要使用'async'模塊方法提前打破時,我實際上使用了這種模式。 – mscdex