如何在客户端返回Meteor.call()的值? [英] How to return value on Meteor.call() in client?
问题描述
所以我一直在使用Twitter Me / MeteorJS,而我正在尝试做的只是在浏览器上显示twitter用户的屏幕名称。这就是我到目前为止所做的:
So I've been using the twitter API w/MeteorJS and what I'm attempting to do is just display the screen name of the twitter user on the browser. This is what I have done so far:
Meteor.methods({
'screenName': function() {
T.get('search/tweets',
{
q:'#UCLA',
count:1
},
function(err,data,response) {
console.log(data.statuses[0].user.screen_name);
return data.statuses[0].user.screen_name;
}
)
}
});
所以我从isClient端调用方法'screenName'。我从我的客户端这样称呼它:
So I call the method 'screenName' from my isClient side. I call it from my client side like this:
var temp = Meteor.call('screenName');
在服务器端,它在控制台上打印出正确的值,但它无法返回值。它一直显示未定义。
On the server side, its printing out the correct value on console but it is not able to return that value. It keeps displaying undefined.
我是一个javascript初学者所以我可能犯了一个错误,我没有马上看到所以如果有人可以请你帮助我,我会非常感谢它。
I am a javascript beginner so I might be making a mistake that I'm not seeing right away so if someone could please help me, I would highly appreciate it.
谢谢!
推荐答案
你需要在里面放一个函数电话是为了能够获得回报。
You need to place a function inside the call to be able to get the return.
Meteor.call(
'screenName',
function(error, result){
if(error){
console.log(error);
} else {
console.log(result);
}
}
);
您可以在有关呼叫功能的文档中阅读更多内容:http://docs.meteor.com/#/full/meteor_call
You can read more in the documentation about the call function: http://docs.meteor.com/#/full/meteor_call
这篇关于如何在客户端返回Meteor.call()的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!