等着流星.客户端的呼叫结果
Wait for Meteor.call result on Client
我是JavaScript新手。我不明白如何等待流星的结果。调用方法。这是我的代码
//client/main.js
//Added the callback
Template.hello.events({
'click button'(event, instance) {
// increment the counter when button is clicked
instance.counter.set(instance.counter.get() + 1);
var res = Meteor.call("callMeLater","sanj",function (err,res) {
if (err) {
console.log(err);
} else {
console.log("this is the result main ", res);
}
});
console.log("this is the result ", res);
}
//server/main.js
Meteor.methods({
callMeLater :function (name) {
var callMeLaterSync =Meteor.wrapAsync(callMeLaterAsync);
var result = callMeLaterSync(name);
console.log("this is the test", result);
return result;
}
});
var callMeLaterAsync = function (name,cb) {
setTimeout(function () {
cb && cb (null ,"hey there, "+name);
},2000);
};
在控制台上,我得到
this is the result undefined
this is the result main hey there, sanj
我如何等待流星的结果。通过在客户端阻塞执行来调用。请帮助
谢谢
只需将代码放入回调方法中。
Meteor.call('callMeLater',"sanj", function(err, res){
if (err) {
console.log(err);
} else {
console.log("this is the result ", res);
}
});
相关文章:
- 奇怪的Javascript结果
- Javascript(jQuery)给了我奇怪的结果
- JSONP请求返回结果,但也触发error_callback
- 如何在chrome扩展中存储数据/结果,以及如何使用setTimeout使其只被调用一次
- Javascript,输出结果后页面不断刷新
- 这是使用html快照和谷歌获取的预期结果吗?SEO/SPA
- 将地理编码结果转换为php变量以发布到mysql数据库
- AngularJS/HTML/Bootstrap元素用于动态搜索结果
- JQuery:向多个匹配结果添加换行符的最简单方法
- 当查询不在displayField中时,引导Ajax Typeahead不显示结果
- webpack代码拆分了handlerbs文件——结果是文件很大
- JavaScript循环无法正确计算/显示结果
- 相同的RegExp返回不同的结果-第一次是正确的结果,第二次是null
- Node.js使用Series函数(模式?)实现流控制时出现意外结果
- 试图将onChange函数作为道具传递给GrandChlidren,结果是TypeError:这是未定义的
- jQuery使用api获取typeform结果
- 根据条件检查数据库结果
- 流星呼叫没有给出任何结果
- 等着流星.客户端的呼叫结果
- 我怎么能等待谷歌远程呼叫返回我的结果之前继续