我正在尝试找出一种方法来为我的应用程序中的每条路线发布数据。 accounts-ui-bootstrap3包查找名为user_profile_picture的值,如果在那里,它将在导航栏中显示头像图像。据我所知,为了使其工作,这些信息需要在铁路由器数据钩子中提供。现在......如果我自己在每条路线上都提供这个,那就行了。但随着更多路线的增加,这会变得混乱和繁琐,所以我希望能够在全球范围内提供这个价值。
我尝试在路由器的配置块(下面)中创建一个全局数据挂钩,但我想数据挂钩仅供控制器使用。
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading',
notFoundTemplate: 'not_found',
waitOn: function() {
return [
subs.subscribe('notifications'),
subs.subscribe('currentUser', {
"_id": true,
"email_hash": true,
"user_profile_picture": true,
"profile": true
})
];
},
data: function() {
return {
user_profile_picture: Meteor.user().user_profile_picture
};
}
});
我也尝试在onAfterAction和onBeforeAction钩子中设置数据,但我认为this.data()是只读的......或者至少在我尝试时它没有添加属性。我也试过
this.data().user_profile_picture = Meteor.user().user_profile_picture;
和
var data = this.data();
data.user_profile_picture = Meteor.user().user_profile_picture;
this.data(data);
但这些也不起作用。我不确定是否可以更改这样的数据,或者我是否错误地更改了数据。
我在那里搜索了文档,并提到了getData()和setData()方法,但文档必须过时,因为那些文档已被删除。
任何想法如何做到这一点?任何帮助表示赞赏。
谢谢。