【发布时间】:2015-03-11 19:13:53
【问题描述】:
我正在尝试加载登录用户的以下用户的食谱(如 Twitter 的主页)。 我正在使用 Iron-Router RoutController。
我想在订阅中查询用户的关注用户食谱和数据,例如:
Recipes.find({
author: {
$in: Meteor.user().followings
}
}, this.findOptions);
但即使我使用“obBeforeAction”,“Meteor.user()”也是未定义的。
所以部分Meteor.subscribe("followingRecipes", Meteor.user().followings, @findOptions())
和 Recipes.find author: $in: Meteor.user().followings ... 未定义。
我是 Meteor 的新手,需要帮助,请帮助我,谢谢。
我的整个代码(CoffeeScript):https://github.com/yhagio/re-cip/tree/style2
//lib/router.js
FollowingRecipesController = RouteController.extend({
template: 'followingRecipes',
increment: 5,
onBeforeAction: function() {
if (!Meteor.user()) {
this.render(this.loadingTemplate);
if (Meteor.loggingIn()) {
this.render(this.loadingTemplate);
} else {
Router.go('/');
}
} else {
this.next();
}
},
postsLimit: function() {
return parseInt(this.params.postsLimit) || this.increment;
},
findOptions: function() {
return {
sort: {
submitted: -1,
votes: -1,
_id: -1
},
limit: this.postsLimit()
};
},
subscriptions: function() {
console.log('subscriptions:', Meteor.user());
this.recipesSub = Meteor.subscribe("followingRecipes", Meteor.user().followings, this.findOptions());
},
recipes: function() {
console.log('recipes:', Meteor.user());
Recipes.find({
author: {
$in: Meteor.user().followings
}
}, this.findOptions);
},
nextPath: function() {
return Router.routes.followingRecipes.path({
username: this.params.username,
postsLimit: this.postsLimit() + this.increment
});
},
data: function() {
var hasMore;
hasMore = this.recipes().count() === this.postsLimit();
return {
recipes: this.recipes(),
ready: this.recipesSub.ready,
nextPath: (hasMore ? this.nextPath() : null)
};
}
});
//server/publications.coffee
Meteor.publish('followingRecipes', function(followings, options) {
return Recipes.find({
author: {
$in: followings
}
}, options);
});
【问题讨论】:
标签: meteor iron-router