我遇到了嵌套float
工作的麻烦,我不知道为什么我收到错误:async.each
即使我已经正确放置了我的回调。
Error: Callback was already called
任何帮助都会非常感激。
答案 0 :(得分:2)
如果符合条件,则在循环浏览next();
后再次呼叫default_shift
。
default_shift.week_days.map(function(day1) {
default_shift2.week_days.map(function(day2) {
if (condition)
next({error: 'The shifts overlap!'}); //The problem is here.
});
});
next(); //If shifts overlap, next was already called.
解决问题的一种简单方法是添加标记,如果移位重叠,则忽略第二个。
var nextCalled = false;
default_shift.week_days.map(function(day1) {
default_shift2.week_days.map(function(day2) {
if (condition && !nextCalled){
next({error: 'The shifts overlap!'});
nextCalled = true;
}
});
});
if(!nextCalled)
next();