从Meteor中的外部API发布数据

时间:2015-06-24 10:02:43

标签: meteor

为了发布来自外部API的项目列表,我遵循了this tutorial:所以我在服务器上发布了一个名为" items"以及客户端上具有相同名称的集合;铁路由器是他们之间的特质联盟。到目前为止一切都很好。

现在我坚持实施"项目细节"路线(例如/ item /:id)。我写了一个像这样的服务器方法:

Meteor.methods({
    'getItem': function(id) {
        check(id, Match.Integer);
        var self = this;
        var asyncCall = Meteor.wrapAsync(requestToThirdParty); 
        // requestToThirdParty is local function which calls HTTP.get
        var response = asyncCall('GET', id);
        return response.data;
    }    
});

我不知道这是否是最佳方式,但我想知道如何从以下路线调用此方法:

Router.route('/items/:id', {
    name: 'itemDetail',
    data: function() {
        var item = Meteor.call('getItem', this.params.id); // this should be sync
        console.log('item: '+item);
        return item;
    }
});

我确定服务器上的方法运行正常(我已调试),但客户端中的控制台日志始终显示" undefined"。

我错过了什么? 还有其他方法吗?

0 个答案:

没有答案