2015-07-20 31 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之前,問題解決了。

相關問題