Meteor 流星如何避免发布所有
我以为我了解Meteor中的酒吧/酒吧,直到我遇到这个问题 假设您有许多供公众使用的博客条目,并且用户导航到/:blogId 你用的是Meteor 流星如何避免发布所有,meteor,Meteor,我以为我了解Meteor中的酒吧/酒吧,直到我遇到这个问题 假设您有许多供公众使用的博客条目,并且用户导航到/:blogId 你用的是 Blogs.findOne(FlowRouter.getParam('blogId')); 目前,在服务器端,我正在发布所有博客条目 Meteor.publish("blogs", function () { return Blogs.find({}); }); 我猜我应该只发布请求的博客条目,比如: Meteor.publish("blogs",
Blogs.findOne(FlowRouter.getParam('blogId'));
目前,在服务器端,我正在发布所有博客条目
Meteor.publish("blogs", function () {
return Blogs.find({});
});
我猜我应该只发布请求的博客条目,比如:
Meteor.publish("blogs", function (_id) {
return Blogs.find(_id);
});
这里的最佳做法是什么?您可以为特定路线制作另一份出版物(仅返回一份)。您的问题完全正确:
Meteor.publish("oneBlog", function (_id) {
return Blogs.find(_id); // must return a *cursor* or array of cursors, not an object
});
Meteor.publish("allBlogs", function () {
return Blogs.find();
});
从客户端根据路由参数订阅oneBlog
:
Meteor.subscribe("oneBlog", FlowRouter.getParam('blogId'));
是的,这是我的假设。您实际使用findOne({})吗?您是否在订阅中传递it参数?我们可以看一个例子吗?它是一个包还是一个普通的集合,你创建的?