1
我想连接我的流星订阅和发布到我的API,发布调用API和返回数据没有问题,但我似乎无法加载我的数据在模板上。流星订阅和发布与外部api
以下是我的代码。
boards.js
import './boards.html';
Tracker.autorun(function() {
Meteor.subscribe('getUserBoards');
});
boards.html
<template name="userBoards">
{{#each boards}}
{{this.id}}
{{/each}}
</template>
index.js
if (Meteor.isServer) {
Meteor.publish('getUserBoards', function getBoards() {
var self = this;
try {
var response = HTTP.get(Meteor.settings.private.api.url+'users/'+this.userId+'/boards/');
_.each(response.data.boards, function(item) {
var doc = {
id: item._id,
name: item.name,
urlFriendlyName: item.urlFriendlyName,
access: item.access,
backgroundImage: item.backgroundImage,
products: item.products,
sharedCount: item.meta.shared,
totalProducts: item.meta.totalProducts,
dateAdded: item.meta.dateAdded
};
self.added('boards', item._id, doc);
});
self.ready();
} catch(error) {
console.log(error);
}
});
}
哪里是你的返回'boards'到'userBoards'模板模板帮手? –
@MichelFloyd这就是我一定会想念的,我该如何去做这件事?对不起,我是流星新手。 –