Dynamically adding a controller to app.js controllers: [] - Ext-JS 4

I have a great application, so I have not added things to my app.js:

stores: [] controllers: [] views: [] models: [] 

Inside, these are just the things I need to build the application. So, when I click on the node (left panel), how can I create the controller that I need and load the model, view, store and other things in this controller? Is it enough to just call the controller (because they are imported into the controller)?

Sort of

 Ext.create('MyApp.path.SomeController'); 

Will it be added in the same way as if I added it to controllers: [] in app.js?

+4
source share
2 answers

My code is very similar to Jenson code.

 // This function loads a controller dynamically and returns its first view // Note: We don't call onLaunch(this) here. This method might be called during // bootstrap (like if there a cookie with the recent page), after which // the application itself will call onLaunch (once out of the Launch method). // The other issue is that the view is not added when this method is called // and we might need to reference the view withing onLaunch, so this is the // wrong place to call on Launch). Currently we're not relying on onLounch // with controllers. dynamicallyLoadController: function( aControllerName ) { // See if the controller was already loaded var iController = this.controllers.get(aControllerName); // If the controller was never loaded before if ( !iController ) { // Dynamically load the controller var iController = this.getController(aControllerName); // Manually initialise it iController.init(); } return iController; }, loadPage: function( aControllerName ) { // save recent page in a controller Ext.util.Cookies.set( 'RecentPage', aControllerName ); var iController = this.dynamicallyLoadController( aControllerName ), iPage = iController.view, iContentPanel = this.getContentPanel(), iPageIndex = Ext.Array.indexOf(iContentPanel.items, iPage); // If the page was not added to the panel, add it. if ( iPageIndex == -1 ) iContentPanel.add( iPage ); // Select the current active page iContentPanel.getLayout().setActiveItem( iPage ); }, 
+2
source

From my app.js, (so this is an Ext JS application):

 addController: function (name) { var c = this.getController(name); //controller will be created automatically by name in this getter //perform the same initialization steps as it would have during normal ExtJs process c.init(this); c.onLaunch(this); } 

name is the name of the class ...

Remember that you can get the instance handle of an application from any other controller using this.application

+3
source

All Articles