Javascript 如何在还原过程中打破?
我想让它像(db.health\u考虑使用多个食物id查找所有数据)->(db.assured\u分析使用多个食物id查找所有数据) 但如果在查找数据时发生错误。我想停止下一步 ex)Javascript 如何在还原过程中打破?,javascript,express,promise,reduce,Javascript,Express,Promise,Reduce,我想让它像(db.health\u考虑使用多个食物id查找所有数据)->(db.assured\u分析使用多个食物id查找所有数据) 但如果在查找数据时发生错误。我想停止下一步 ex) 您可以在减少-ing之前切片数组。(arr.slice(0,arr.length-3).reduce())通常,在还原开始后不会中断还原。Clojure是我所知道的唯一一种允许提前退出的语言。.reduce是同步完成的。如果您希望以异步方式使用.reduce,您可能需要查看RxJS。 data_set.reduc
您可以在
减少-ing之前切片数组。(arr.slice(0,arr.length-3).reduce()
)通常,在还原开始后不会中断还原。Clojure是我所知道的唯一一种允许提前退出的语言。.reduce
是同步完成的。如果您希望以异步方式使用.reduce
,您可能需要查看RxJS。
data_set.reduce(function(prev,curr,index,arr){
return prev.then(function(){
db.health_consideration.findAll({
where:{ FoodId : curr.id }
}).then(function(ing_sets){
sumData[2].push(ing_sets);
if(index == arr.length-3){
//I want to break this point.
}
if(index == arr.length-1){
console.log('wow3');
console.log(sumData[2].length);
data_set.reduce(function(prev,curr,index,arr){
return prev.then(function(){
db.guaranteed_analysis.findAll({
where:{ FoodId : curr.id }
}).then(function(ing_sets){
sumData[3].push(ing_sets);
if(index == arr.length-1){
console.log('wow4');
console.log(sumData[3].length);
}
})
.catch(function(e){
console.log(e);
});
})
},Promise.resolve())
.catch(function(e){
console.log(e);
})
}
})
.catch(function(e){
console.log(e);
});
})
},Promise.resolve())
.catch(function(e){
console.log(e);
})
if(index == arr.length-3){
//I want to break this point.
}