我正在使用Backbone.js路由配置文件视图,以便我可以查看属于/ user的数据,并且该部分工作正常。我能够根据用户名生成一个_id并将其传递给服务器发布功能,该功能会记录它。但是,当我在subscribe函数中将结果记录回客户端时,我的结果如下所示:
对象{stop:function,ready:function}
//Client Side
Template.userquery.userproject = function() {
var query = Session.get('userquery');
var user = Meteor.users.findOne({username: query});
if (user) {
console.log(user._id); //(works)
campaigns = Meteor.subscribe('userquery', user._id, function() {
console.log('ready'); //(works)
});
console.log(campaigns); //(returns Object {stop: function, ready: function})
return campaigns;
}
}
//Server Side
Meteor.publish('userquery', function(userid) {
console.log('break');
console.log(userid); //(I get userid in Terminal)
var campaigns = Campaigns.find({owner: userid}, {fields: {owner: 1, name: 1}});
if (campaigns) {
console.log(campaigns);
return campaigns;
}
});
我在这个功能中遗漏了什么?我关闭了autopublish,因为它生成了我的搜索两次。