2012-06-07 2 views
2

je le StateManager suivant qui traite quelques vues. Je ne voudrais pas avoir à passer manuellement dans l'état initial avec App.stateManager.transitionTo('showingPhotos'). Je préfère juste utiliser la propriété initialState du gestionnaire d'état. L'utilisation de la propriété initialState du StateManager ne fonctionne cependant pas dans ce cas car les contrôleurs ne sont pas disponibles tant qu'ils ne sont pas injectés avec App.initialize(App.stateManager).Ember StateManager, l'injection des contrôleurs et en utilisant initialState

Est-il possible d'éviter d'avoir à passer manuellement à l'état initial tout en injectant les contrôleurs? Existe-t-il un meilleur moyen de structurer un gestionnaire d'état comme celui-ci?

J'ai créé deux JSfiddles:

http://jsfiddle.net/GmD8A/ - cela fonctionne, mais je dois passer manuellement dans l'état initial

http://jsfiddle.net/tgbuX/ - utilise ce initialState plutôt que la transition manuellement dans l'état initial et par conséquent ne pas travail.

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 

Répondre

Questions connexes