0

我在具有不同数据参数但使用相同出版物的其他路线中重用相同的模板...

如果我进行正常的发布/订阅,则数据将按预期发布。但是当我像下面那样进行有条件的发布/订阅时,我无法订阅数据。控制台日志返回空数组,,,

服务器/publication.js

Meteor.publish('ACStats', function(cId, uId) {
    var selectors = {cId:cId, uId:uId};
    var options = {
        fields: {qId:0}
    };
    return ACStats.find(selectors,options);
});

客户端/onCreated

Template.channelList.onCreated(function() {
  this.disable = new ReactiveVar('');
  if (FlowRouter.getRouteName() === 'profile') {
    var self = this;
    self.autorun(function() {
      var penName = FlowRouter.getParam('penName');
      var u = Meteor.users.findOne({slugName:penName});
      if (u) {var uId = u._id;}
      Meteor.subscribe('ACStats', null, uId);
    });
  } else{
    var self = this;
    self.autorun(function() {
      var channelName = FlowRouter.getParam('channel');
      var c = Channels.findOne({title:channelName});
      if (c) {var cId = c._id;}
      Meteor.subscribe('ACStats', cId, null);
    });
  }
});

安慰

ACStats.find().fetch() //return empty array

有人发现我的错误..??

太感谢了....

4

1 回答 1

0

您可以制作两个出版物:

Meteor.publish ('ACStatsChannels', cId, function() {
});
Meteor.publish ('ACStatsUsers', uId, function() {
})

然后像这样订阅:

Template.channelList.onCreated(function() {
   this.disable = new ReactiveVar('');
   var self = this;
   self.autorun(function() {
      if (FlowRouter.getRouteName() === 'profile') {
          var penName = FlowRouter.getParam('penName');
          self.subscribe('ACStatsUsers', penName);
      } else {
          var channelName = FlowRouter.getParam('channel');
          self.subscribe('ACStatsChannels', channelName);
    }
  });
});
于 2016-01-13T15:49:22.237 回答