如何根据 url 使 Meteor Collection 无反应? [英] How to make a Meteor Collection non reactive depending on a url?

查看:42
本文介绍了如何根据 url 使 Meteor Collection 无反应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用流星构建一个磁性诗歌游戏,我很喜欢它.

Hi I am building a magnetic poetry game with meteor which I am pretty green with.

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

目前它是协作式的,效果很好.我现在正试图拥有它,以便您可以私下玩耍,而不会有人打扰您的诗.我使用 Iron Router 根据用户 ID 生成 url

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

router.js

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

我有在磁铁中使用冰箱 ID 的想法.在家庭协作中,冰箱 ID 为 1.当您单击创建我自己的时,它会将冰箱 ID 更改为与用户 ID 相同.我假设我需要根据冰箱 ID 进行某种发布和订阅,但不确定如何做.

I had the idea of using a fridgeId within the magnets. 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. I am assuming I need to do some sort of publishing and subscribing based on the fridgeId but not sure how to.

这会将冰箱 ID 切换为用户 ID

this switches the fridgeId to the user 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});
}

然后这将主页上的冰箱 ID 设置回 1

then this sets the fridgeId back to 1 on the home page

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

当前订阅和发布

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

-约翰

推荐答案

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

这篇关于如何根据 url 使 Meteor Collection 无反应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆