我有一个带有两个出口的应用程序模板的应用程序。当我进入 root.index 状态时,我只想连接一个 outlet,当我进入 root.chats 状态时,我希望两个 outlet 都连接。当我从 root.index 导航到 root.chats 时,这很好用,但是当我返回时,导航窗格出口仍然存在(应该如此)。如何断开此插座或删除最初连接的视图?控制器 mixin 的 disconnectOutlet 方法是否已弃用?我应该以完全不同的方式构建它吗?我在下面包含了我的代码。谢谢。
// State flag helper function. See https://github.com/ghempton/ember-router-example/blob/master/js/app.js
function stateFlag(name) {
return Ember.computed(function() {
var state = App.router.currentState;
while(state) {
if(state.name === name) return true;
state = state.get('parentState');
}
return false;
}).property('App.router.currentState');
}
// Application
App = Em.Application.create({
ApplicationController: Ember.Controller.extend({
isChats: stateFlag('chats')
}),
ApplicationView: Ember.View.extend({
templateName: 'application'
}),
ChatlistController: Em.Controller.extend({
hideView: false
}),
ChatlistView: Em.View.extend({
templateName: 'chatlist',
didInsertElement: function(){
this.$("#nav_pane").css({'left':'-=275', 'z-index':'-5'}).animate({
left: ["+=275", 'swing'],
},500,function() {
$(this).css('z-index','5')
});
},
_hideViewChanged: function() {
if (this.get('hideView')) {
this.hide();
}
}.observes('hideView'),
hide: function() {
var that = this;
this.$("#nav_pane").hide("slow", function() {
that.remove();
});
}
}),
ChatroomController: Em.Controller.extend({
}),
ChatroomView: Em.View.extend({
templateName: 'chatroom'
}),
DashboardController: Em.Controller.extend({
}),
DashboardView: Em.View.extend({
templateName: 'dashboard'
}),
Router: Ember.Router.extend({
//location: 'history',
enableLogging: true,
goToDashboard: Ember.Route.transitionTo('root.index'),
goToChats: Ember.Route.transitionTo('root.chats'),
root: Ember.Route.extend({
index: Ember.Route.extend({
route: '/',
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('content', 'dashboard');
}
}),
chats: Ember.Route.extend({
route: '/chats',
connectOutlets: function(router, context) {
router.get('applicationController').connectOutlet('navpane', 'chatlist');
router.get('applicationController').connectOutlet('content', 'chatroom');
}
}),
files: Ember.Route.extend({
route: '/files'
})
})
})
});
App.initialize();