问题描述
所以我一直在使用带有 MeteorJS 的 twitter API,我试图做的只是在浏览器上显示 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() 上返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!