Returning data from Parse promise chain

女生的网名这么多〃 提交于 2019-12-05 22:10:48

You don't return :)

I'm sorry, that is just a joke on a technicality: you see, Promises are a way to express asynchronous behaviour. So you can't, strictly saying, grab the return value of a function.

However, you are already grabbing the results of each step correctly... You just didn't realize you can use it yourself.

The answer is to use your own then handler.

user_comp_query.find().then(a).then(b).then(function(results){
  console.log(results); // Hooray!
});

However, keep in mind that a Promise might fail. That's why it's important to pass a second handler, which will be called whenever there is an error.

var handleSuccess = function (results) {};
var handleFailure = function (error) {};
var parsePromise = user_comp_query.find().then(a).then(b);
parsePromise.then(handleSuccess, handleFailure);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!