我正在做一个基于 ember 的项目,但我不确定设计。我有一个所有其他控制器都在扩展的应用程序控制器:
基本控制器
App.ApplicationController = Ember.Controller.extend({
needs:['userNav'],
dateNavSelected : '',
currentSleeperImg:AppStateManager.get('currentSleeperImg'),
currentSleeperName:AppStateManager.get('currentSleeperName'),
didSleeperChange:false,
logout: function(){
AppStateManager.transitionTo('loggedOutState');
this.transitionToRoute('signin');
},
selectSleeper: function(sleeper){ //Gets the sleeper change from the menu
var currSleeper = AppStateManager.get('currentSleeperObj');
if(!currSleeper || (currSleeper && sleeper.get('id') != currSleeper.get('id'))){
AppStateManager.set('currentSleeperImg', sleeper.get('sleeper_avatar'));
AppStateManager.set('currentSleeperName', sleeper.get('sleeper_name'));
AppStateManager.set('currentSleeperObj', sleeper );
this.set('currentSleeperImg' , sleeper.get('sleeper_avatar'));
this.set('currentSleeperName' , sleeper.get('sleeper_name'));
this.set('didSleeperChange', true);
}else{
this.set('didSleeperChange', false);
}
}
});
子控制器
App.LastNightSummaryController = App.ApplicationController.extend({
pageTitle: moment().subtract('days', 1).format("MMM D"),
active:'last-night-summary',
selectSleeper: function(sleeper){ //Gets the sleeper change from the menu
this._super(sleeper);
if(this.get('didSleeperChange')){
this.set('content', App.SleepData.find({id:sleeper.get('id'), sleeper:sleeper}));
}
}
});
是好的模式吗?