【发布时间】:2017-04-26 09:33:18
【问题描述】:
Meteor.call 中的异步回调不等待 Meteor.method 的结果。这是代码。
Meteor.call("fetchData",function (err,res) {
if (err){
console.log("error ", err);
}else {
console.log("success ", res);
return res;
}
});//calling this from onRendered of client/somejs.js
方法如下
fetchData :function(){
HTTP.call("POST","http://localhost:8080",{
data:'{"apple":"grape"}'
},function (err,res) {
if (err){
console.log("error ", err);
}else {
console.log("success ", res);
return res;
}
})
}//Server/methods.js
当 Meteor.call 被触发时,我会在服务器上以success 的形式记录其结果。
在客户端我得到 success undefined 。
客户端上的调用不等待结果。我还尝试在服务器上执行 Fibers 和同步执行。它对我不起作用。在这种情况下,发布被阻止(我猜是由于 API 调用)。
另一件事是我尝试使用数据库查询而不是 API 调用进行相同的操作。效果很好。我从方法中得到结果。
我哪里出错了。求助。
谢谢
【问题讨论】:
标签: javascript meteor