简体   繁体   English

如何根据URL使Meteor Collection不起作用?

[英]How to make a Meteor Collection non reactive depending on a url?

Hi I am building a magnetic poetry game with meteor which I am pretty green with. 嗨,我正在用流星制作一个磁性诗歌游戏,我对它相当环保。

http://test-magnets.meteor.com/ http://test-magnets.meteor.com/

Currently it is collaborative it works great. 目前它是协作的,效果很好。 I am now trying to have it so that you can play privately without people messing with your poems. 我现在正尝试拥有它,这样您就可以私下演奏而不会被别人弄乱您的诗歌。 I used Iron Router to generate a url based on the userID 我使用Iron Router根据用户ID生成了一个url

router.js router.js

Router.map(function() {
this.route('home', {
    path: '/'
});
var user = Meteor.userId();
this.route('private', {
    path: '/' + user
   });
});

I had the idea of using a fridgeId within the magnets. 我的想法是在磁铁中使用RefrigeratorId。 On the home collaborative are the fridgeId is 1. When you click on create my own, it changes the fridgeId to the same as the userId. 在家庭协作中,RefrigeratorId为1。单击“创建我自己的”时,它会将FisherId更改为与userId相同。 I am assuming I need to do some sort of publishing and subscribing based on the fridgeId but not sure how to. 我假设我需要根据RefrigeratorId进行某种发布和订阅,但不确定如何进行。

this switches the fridgeId to the user id 这会将RefrigeratorId切换为用户ID

  'click #new-board': function() {
    var user = Meteor.userId();
    var magnet = Magnets.findOne();
    Magnets.update({_id: magnet._id}, {$set: {fridgeId: user}});
    return Magnets.find({fridgeId: user});
}

then this sets the fridgeId back to 1 on the home page 然后在首页上将RefrigeratorId设置回1

Template.private.events = {
   'click #group-play': function() {
    var magnet = Magnets.findOne();
    Magnets.update({_id: magnet._id}, {$set: {fridgeId: 1}});
    return Magnets.find({fridgeId: 1});
  }
};

current subscribe and publish 当前订阅和发布

if (Meteor.isClient) {

Meteor.subscribe('magnets', function() {
    return Magnets.find();
 });
}

if (Meteor.isServer) {
  Meteor.publish('magnets', function() {
    return Magnets.find();
  });
 }

any suggestions would be greatly appreciated. 任何建议将不胜感激。 Thanks 谢谢

-John -约翰

return Magnets.find({fridgeId: user},{reactive: false});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM