我有以下StateManager其與幾個視圖交易。我不想用App.stateManager.transitionTo('showingPhotos')
手動轉換到初始狀態。我寧願只使用州經理的財產initialState
。灰燼StateManager,注入控制器和使用的初始化狀態
在這種情況下使用StateManager的initialState
屬性不起作用,但是因爲控制器在注入App.initialize(App.stateManager)
之前不可用。
有一種方法,以避免手動轉換到初始狀態,同時還注入控制器?有沒有更好的方式來組織像這樣的國家經理?
我已經創建了兩個JSfiddles:
http://jsfiddle.net/GmD8A/ - 這個工作,但我必須手動轉換到初始狀態
http://jsfiddle.net/tgbuX/ - 這款採用initialState
而不是手動轉換到初始狀態,因此不工作。
PhotosListView = Ember.View.extend({
template: Ember.Handlebars.compile('<h2>Showing Photos</h2><a {{action "showContacts"}}>Show Contacts</a>')
});
ContactsListView = Ember.View.extend({
template: Ember.Handlebars.compile('<h2>Showing Contacts</h2><a {{action "showPhotos"}}>Show Photos</a>')
});
StateManager = Ember.StateManager.extend({
rootElement: '#body',
showingContacts: Ember.ViewState.extend({
view: ContactsListView,
showPhotos: function(manager) {
manager.transitionTo('showingPhotos');
},
enter: function(manager) {
this._super(manager);
this.setPath('view.controller', manager.get('photosController'));
}
}),
showingPhotos: Ember.ViewState.extend({
view: PhotosListView,
showContacts: function(manager) {
manager.transitionTo('showingContacts');
},
enter: function(manager) {
this._super(manager);
this.setPath('view.controller', manager.get('contactsController'));
}
})
});
App = Ember.Application.create()
App.PhotosController = Ember.ArrayController.extend()
App.ContactsController = Ember.ArrayController.extend()
App.stateManager = StateManager.create()
App.initialize(App.stateManager) // This injects the controllers
App.stateManager.transitionTo('showingPhotos') // I don't want to have to manually transition into this initial state