3
我想弄清楚承诺是如何在sails中工作的,并且已经成功地从水线查询中通过.then传递数据,但尚未能够利用.spread 。我收到一个函数未定义的错误。任何建议如何可以改善第一部分代码的工作?node.js sails.js waterline bluebird .then和.spread
//results in error
Promise.all([Xyz.find(), Abc.find()]).spread(function (someOtherResult, yetAnotherResult) {
console.log(someOtherResult)
}).catch(function (err) {
console.log(err);
})
下工作,但将是要么棘手提取数据,或者需要过长的嵌套。于是条款:
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
}))
})