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這就是我一定會想念的,我該如何去做這件事?對不起,我是流星新手。 –