2017-07-27 58 views
0

Promise.All返回數組下面的查詢成功註銷查詢結果:Sequelize - 未定義

loans.findAll({ 
     attributes: option.LoanAttributes, 
     include: option.LoanIncludes 
     }).then(results => { 
     console.log(ExtractQuery(results)); 
    }); 

然而,當我一個promise.all函數內包裝它,它會返回未定義的數組:

Promise.all([ 
     loans.findAll({ 
     attributes: option.LoanAttributes, 
     include: option.LoanIncludes 
     }) 
    ]).then(results => { 
     console.log(ExtractQuery(results)); 
    }) 

回答

4

Promise.all(promiseArraySizeN).then(fulfilledPromiseArraySizeN)

您有一個大小爲1的承諾數組,因此它將返回一個滿足大小爲1的承諾數組。因此,您需要檢查r esults [0]。

Promise.all([ 
    loans.findAll({ 
    attributes: option.LoanAttributes, 
    include: option.LoanIncludes 
    }) 
]).then(results => { 
    console.log(ExtractQuery(results[0])) 
}) 
相關問題