2015-07-20 61 views
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 
     })) 
    }) 

回答

2

好了,很简单的错误,我没有意识到我需要:

var Promise = require('bluebird');

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

相关问题