在使用bluebird 的promise 时 写法如下.
var result = null;
Promise.resolve(result)
.then(function(result){
//1
result = xxxService.findOne({id:xxx});
}).then(function(){
//2
console.log(result);
})
xxxService.findOne({id:xxxx},function(err,doc){
return doc;
});
手写代码可能不对. 大概这个意思.
问题: 我在 步骤 2 里调用 result时没有值.
如何 能等findOne 的回调执行完了 再 走 第二个then 方法?
不使用promise 用回调能解决我的问题 .可是我想用promise来解决.
或者 有什么其它好的方案么?
谢谢指导.