我试图让 2 个小部件出现在 ember.js 应用程序的多个路由中。我已经设置了以下作为演示,http://jsfiddle.net/adice/EyDcy/5/
您会看到我已经找到了一种方法,方法是将以下内容添加到路由中:
App.IndexRoute = Em.Route.extend({
setupController: function(controller,model) {
this._super(controller,model);
controller.set('user',App.UsersStore.find(2));
controller.set('site',App.SiteData.find(1));
}
});
但是,如果我想让它适用于每条路线,我真的必须手动将它添加到我制作的所有路线中吗?我试图将它添加到 ApplicationRoute,但一直返回错误。
还有一种填充id的方法吗?我想做
App.appData = Em.Object.create({
currentUserId: 2
});
App.IndexRoute = Em.Route.extend({
setupController: function(controller,model) {
this._super(controller,model);
controller.set('user',App.UsersStore.find(App.appData.currentUserId));
controller.set('site',App.SiteData.find(1));
}
});