Meteor 服务器方法未将数据返回到客户端

Meteor 服务器方法未将数据返回到客户端,meteor,Meteor,下面是位于server\twitter\methods.js Meteor.startup(function(){ Meteor.methods({ searchTweets:function(term){ T.get('search/tweets', { q: term, count: 2 }, function(err, data) { console.log(data); ret

下面是位于
server\twitter\methods.js

Meteor.startup(function(){
    Meteor.methods({
        searchTweets:function(term){
            T.get('search/tweets', { q: term, count: 2 }, function(err, data) {
                console.log(data);
                return data;
            })
        }
    });
});
Template.DashboardSearch.events({
    "click #btnSearchTweets": function(event, template){
        event.preventDefault();
        var term = $('#searchTerm').val();

        Meteor.call('searchTweets', term, function(err, result) {
            console.log(err);
            console.log(result);
            if (err) {
                console.log(err);
            }
            if (result) {
                Session.set('tweetData', result);
            }
        });
        $('#searchTerm').val("");
    }
});
以下是位于
client\search.js

Meteor.startup(function(){
    Meteor.methods({
        searchTweets:function(term){
            T.get('search/tweets', { q: term, count: 2 }, function(err, data) {
                console.log(data);
                return data;
            })
        }
    });
});
Template.DashboardSearch.events({
    "click #btnSearchTweets": function(event, template){
        event.preventDefault();
        var term = $('#searchTerm').val();

        Meteor.call('searchTweets', term, function(err, result) {
            console.log(err);
            console.log(result);
            if (err) {
                console.log(err);
            }
            if (result) {
                Session.set('tweetData', result);
            }
        });
        $('#searchTerm').val("");
    }
});

问题是,search.js文件中的2
console.log()
语句都返回
undefined
,而methods.js中的
console.log()
语句返回预期的twitter api数据,有什么线索吗?

我可能误导了一些人,让他们知道我是如何提出问题的

事情是这样的;我使用的是MeteoHacks:npm包,
T
表示一个
Meteor.npmRequire()

这就是我的方法现在的样子:

Meteor.methods({
    searchTweets:function(term){
        var tweets = Async.runSync(function(done) {
            T.get('search/tweets', { q: term, count: 2 }, function(err, data) {
                done(null, data);
            });
        });
        return tweets.result;
    }
}); 

现在一切似乎都正常工作。

将该方法放入共享文件夹。并在Template.rendered函数中调用它。同时将其从Meteor.startup、Meteor.methods中移出-alone@S.19LaBG谢谢你的反馈,但这并没有解决问题。@Sindis正在调试这个东西,并试图将它放在启动函数中。如果您感兴趣,我会在下面发布我的答案。您需要使用“同步”(包装异步)HTTP调用或返回承诺。有关承诺选项,请参见。