我一直對我的頭撞牆了一段時間,我假設我在這裏錯過了一些簡單的東西。客戶端訂閱無法從Meteor服務器接收數據發佈
我我的流星服務器上運行此:
// --- Collections ---
Projects = new Meteor.Collection('projects');
Team = new Meteor.Collection('team');
// --- Only publish user data for users on my team ---
Meteor.publish('team', function() {
var team = Meteor.users.findOne({_id: this.userId}).profile._team;
console.log(Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}}).fetch());
return Meteor.users.find({'profile._team': team}, {fields: {_id: 1, profile: 1}});
});
此找到所有誰是在同一個「團隊」的網友通過對誰具有相同的ID中的所有用戶文件運行查詢profile._team
屬性作爲當前登錄的用戶。你會在發佈函數中看到console.log(...);
(在return語句之前的那行),並且它正確地記錄了我期望它在我的終端中的文檔。
現在我爲我的客戶端上運行此:
// --- Data ---
Meteor.subscribe('team');
Team = new Meteor.Collection('team');
Template.team.team = function() {
console.log(Team.findOne());
return Team.find();
};
然而,console.log(Team.findOne())
始終記錄不確定,Team.find()
總是返回一個空數組。我做錯了什麼,阻止我的文檔到達客戶端?
UPDATE:以下是模板代碼。
<body>
{{> team}}
</body>
<template name="team">
<p>TEAM TEMPLATE WORKS</p>
{{#each team}}
<p>TEAM EACH WORKS</p>
<div class="teamMember">
{{profile.firstName}} {{profile.lastName}}
</div>
{{/each}}
</template>
「隊中的每一作品」永遠不是{{#each}}
標籤內呈現,但「TEAM模板工程」呈現時,它被放置在{{#each}}
標記之前預期。
的東西就很奇怪。請發佈您的模板代碼。 – Xyand
添加了模板代碼。 –
它有助於瞭解客戶端通常需要使用與服務器相同的集合名稱,但預訂名稱可能完全不同,並且需要與發佈名稱(*不是服務器上的集合名稱)匹配。查看詳情[流星收藏,訂閱和出版物如何工作](http://stackoverflow.com/a/21853298/1269037)。 –