Meteor publish - 如何使用配置文件信息发布数据和检查

时间:2013-10-02 19:42:48

标签: javascript meteor publish-subscribe

我的问题很简单,但遗憾的是我没有找到任何地方。

我有一组地图,例如我正在使用Meteor.user()。profile.mapsId来检查是否 该用户可以看到该地图。

第一种方法:

服务器/ server.js

Meteor.publish('map', function (mapOwner) {
  var user =  Meteor.user();
  var mapId = user.profile.mapId;
  return Map.find({mapOwner: mapId});
});

无法正常工作,因为发布不接受Meteor.user();

第二种方法:

服务器/ server.js

    Meteor.publish('map', function (mapOwner) {
          return Map.find({mapOwner: Meteor.call('mapsCall')});
        });

集合/ maps.js

Map = new Meteor.SmartCollection('map');

Meteor.methods({
  mapsCall: function() {
  var user = Meteor.user();
  var startupId = user.profile.startupId;
  return startupId;
  }
});

当我调用Map.find()时,fetch()没有任何东西..

什么是正确的方法?

1 个答案:

答案 0 :(得分:3)

第一种方法看起来是正确的,但您需要以另一种方式加载用户,因为Meteor.user()在发布函数中不可用。只是做:

var user = Meteor.users.findOne(this.userId);
相关问题