问题
Hi I am building a magnetic poetry game with meteor which I am pretty green with.
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
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. 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.
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});
}
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});
}
};
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
回答1:
return Magnets.find({fridgeId: user},{reactive: false});
来源:https://stackoverflow.com/questions/28075985/how-to-make-a-meteor-collection-non-reactive-depending-on-a-url