node.js sails.js waterline bluebird .then and .spread

node.js sails.js waterline bluebird .then and .spread

我正在尝试弄清楚 promises 在风帆中是如何工作的,并且已经成功地通过 .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
        }))
    })

好吧,非常简单的错误,我没有意识到我需要:

var Promise = require('bluebird');

在 sails.js .11 中的 module.exports 之前,问题已解决。