【发布时间】:2016-11-27 21:53:54
【问题描述】:
我是 Meteor 和 Angular 2 的新手,我正在努力列出我的客户端中的所有用户。据我了解,我必须在我的服务器上发布并在我的客户端上订阅,我这样做了以下方式:
users.ts
import {Meteor} from 'meteor/meteor';
Meteor.publish('usersList', function () {
console.log('Publish from server ');
return Meteor.users.find({_id: {$ne: Meteor.userId()}});
});
但是,这甚至没有被调用。我将这个文件导入到我的 main.ts 中。我不确定我应该如何发布它们以吸引所有用户。
我已通过关注Meteor-Angular2 tutorial 创建了另一个集合。该文件如下: wishs.ts
import {Meteor} from 'meteor/meteor';
import {Wishes} from '../../../both/collections/wishes.collection';
Meteor.publish('wishList', function () {
console.log("wishlist "+this.userId);
return Wishes.find(buildQuery.call(this));
});
function buildQuery(): Object {
const isAvailable = {
$and: [{
owner: this.userId
}, {
owner: {
$exists: true
}
}]
}
return isAvailable;
}
我在服务器的 main.ts 中调用它,它正在工作。我不知道为什么其中一个文件被调用,而另一个文件为什么不被调用。任何方向将不胜感激!
【问题讨论】: