我使用此方法动态创建集合:
createPlist: function(jid) {
try {
Plist[jid] = new Meteor.Collection(pid);
} catch(e) {
console.log("oops, I did it again");
}
Plist[jid].insert({
...,
...,
public:true,
uid:this.userId
});
}
然后我想有选择地发布这些,我试图通过一种方法来实现:
getPlist: function(jid,pid) {
// var future = new Future();
try {
Plist[jid] = new Meteor.Collection(pid);
} catch(e) {
console.log("oops, I did it again");
}
Meteor.publish(pid, function() {
console.log(Plist[jid].find({}));
// future["return"](Plist[jid].find({}));
return Plist[jid].find();
});
// return future.wait();
},
这会返回' undefined'到我的模板助手,并使用Future返回任何内容(即永远等待)。
任何用户都可以登录并创建Plist集合,该集合可以是公共的也可以是公共的。用户还可以订阅公共为真的任何集合。变量jid传递给方法' getPlist'从模板。它存储在用户的会话中。
谢谢!我希望我已经解释得很好了!
当然还有模板:
Template.plist.helpers({
getPlist: function() {
Pl = []
jid = Session.get('jid');
//alert(jid);
pid = "pl_"+jid;
// console.log(pid);
Meteor.call('getPlist', jid, pid, function(err,res) {
console.log(res); //returns undefined
try {
Pl[jid] = new Meteor.Collection(pid);
} catch(e) {
console.log(e);
}
Meteor.subscribe(pid);
// return Pl[jid].find({}).fetch();
});
}