我正在尝试弄清楚sails中的承诺是如何工作的,已经成功地通过.then传递水线查询数据,但是无法利用.spread。我收到一个未定义的函数错误。有什么建议可以改进代码的第一部分以使其正常工作吗?
//results in error
Promise.all([Xyz.find(), Abc.find()]).spread(function (someOtherResult, yetAnotherResult) {
console.log(someOtherResult)
}).catch(function (err) {
console.log(err);
})
以下代码可以正常运行,但要从中提取数据可能会更加困难,或需要过长的嵌套.then语句:
Promise.all([Xyz.find(), Abc.find()]).then(function (results) {
console.log(results[0][1]);
console.log(results[0].length);
})
Abc.find().then(function (foundAbcs) {
Promise.all(Xyz.find().then(function (foundXyzs) {
console.log(foundAbcs);
console.log(foundXyzs);
// additional syncranouse logic with Abc and Xyz
}))
})