Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/468.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在还原过程中打破?_Javascript_Express_Promise_Reduce - Fatal编程技术网

Javascript 如何在还原过程中打破?

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

我想让它像(db.health\u考虑使用多个食物id查找所有数据)->(db.assured\u分析使用多个食物id查找所有数据)

但如果在查找数据时发生错误。我想停止下一步

ex)


您可以在
减少
-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. 
            }