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