【发布时间】:2014-01-02 04:33:05
【问题描述】:
我的 Meteor 项目中有以下数据结构:
- 具有一组属于用户(作者)的列表 ID 的用户
- 列表实际上包含列表的所有数据和一组允许查看它的用户 ID(和所有者)
现在我正在尝试使用 publish-with-relations-package (Toms version from GitHub) 将用户的所有列表发布到客户端。这是一个简单的例子:
Lists = new Meteor.Collection("lists");
if (Meteor.isClient) {
Deps.autorun(function() {
if (Meteor.userId()) {
Meteor.subscribe("lists");
}
});
Template.hello.greeting = function () {
return "Test";
};
Template.hello.events({
'click input' : function () {
if (typeof console !== 'undefined')
console.log(Lists.find());
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
if ( Meteor.users.find().count() === 0 ) {
var user = Accounts.createUser({ //create new user
username: 'test',
email: 'test@test.com',
password: 'test'
});
//add list to Lists and id of the list to user
var listid = new Meteor.Collection.ObjectID().valueOf();
Meteor.users.update(user._id, {$addToSet : {lists : listid}});
Lists.insert({_id : listid, data : 'content', owner : user._id});
}
});
Meteor.publish('lists', function(id) {
Meteor.publishWithRelations({
handle: this,
collection: Lists,
filter: _id,
mappings: [{
key: 'lists',
collection: Meteor.users
}]
});
});
Meteor.publish("users", function(){
return Meteor.users.find({_id : this.userId});
});
//at the moment everything is allowed
Lists.allow({
insert : function(userID)
{
return true;
},
update : function(userID)
{
return true;
},
remove : function(userID)
{
return true;
}
});
}
发布不起作用,并且光标不包含启动的 List 元素。
知道如何解决此反应式联接以发布某个用户的列表吗?提前致谢,感谢您的帮助!
【问题讨论】:
标签: javascript mongodb meteor