PDA

View Full Version : Dynamic creation of view and controller



martinrame
10 Feb 2012, 10:28 AM
In an event handler in one controller, I need to open a view and its associated controller, currently I'm doing this:


mycontroller = this.getController('DEMO.controller.UserCRUD');
myview = Ext.create('DEMO.view.UserCRUD', {});
myview.show();
mycontroller.init();

But this doesn't looks nice. Is there a way to autommatically link the view and controller in a way that instantiating one of them, the other is created automatically?.

Thanks in advance,
Leonardo.

mitchellsimoens
10 Feb 2012, 10:42 AM
Your controllers should be loaded upfront.

martinrame
11 Feb 2012, 6:31 AM
Do you mean defined in my app.js?

dedoz
11 Feb 2012, 1:03 PM
you can


mycontroller = this.getController('DEMO.controller.UserCRUD');
mycontroller.init();


and inside your init method, create the controller view and all its stuff. with show and everything :d

im developin a software like that, after user clicks a menu, i load the corresponding controller and then call its init method after controllers dependency are loaded.