Bre*_*ain 0 mongodb meteor iron-router meteor-helper
我有在服务器端发布的集合,并使用铁路由器的waitOn订阅这些集合.但是,在客户端,我永远看不到对服务器端定义的集合的任何引用.我可以访问它们的唯一方法是在客户端定义集合(devices = new Meteor.Collection('devices')),但我没有看到有人在他们的在线示例中这样做.这是代码:
客户代码:
Router.route('/devices', {
waitOn: function() {
return [
Meteor.subscribe('devices', Meteor.user()._id),
];
},
action: function() {
this.render();
}
});
Run Code Online (Sandbox Code Playgroud)
服务器端:
Devices = new Mongo.Collection("devices");
Devices.allow({
'insert': function (userId, doc) {
if (userId === doc.accountId) {
return true;
}
return false;
},
'update': function (userId, doc) {
if (userId === doc.accountId) {
return true;
}
return false;
},
});
Meteor.publish('devices', function(id) {
return Devices.find({accountId: id});
});
Run Code Online (Sandbox Code Playgroud)
我已经删除了自动发布,并且从在线示例中,我应该能够引用Devices.find({}).相反,我必须使用devices = new Meteor.Collection('devices')然后引起问题,因为如果我再次调用它,它会说我已经有一个名为devices的集合.有谁知道为什么我不能参考设备?
您无法在客户端引用它的原因是您尚未将该集合提供给客户端.
保留服务器端.allow
和.publish
方法,但将集合创建移动到lib文件夹,以使其在客户端和服务器上都可用.
/lib/collections.js:
Devices = new Mongo.Collection("devices");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1126 次 |
最近记录: |