-
7 Oct 2011 4:30 AM #1
Answered: MVC change view from one to another in the controller
Answered: MVC change view from one to another in the controller
Hi
I have a controller with two views. In one of the views a have a button with a click listener. On that click i want to change the view from one to the other. Whats the best way to do this?
I already have the click listener in place so the only thing i need to know is how to switch views.
-
Best Answer Posted by arthurakay
Changing the view depends on your layout.
It would be the same as adding/removing or showing/hiding parts of any widget in the framework. Card layouts would call setActiveItem(), whereas Fit layouts might have to completely destroy their children items.
Assuming your application is simply a viewport displaying some panel, your controller would simply ask the viewport to hide/remove the existing view, and show/add the new view. Calling doLayout() might need to happen as well, depending on your setup.
-
7 Oct 2011 5:44 AM #2
Changing the view depends on your layout.
It would be the same as adding/removing or showing/hiding parts of any widget in the framework. Card layouts would call setActiveItem(), whereas Fit layouts might have to completely destroy their children items.
Assuming your application is simply a viewport displaying some panel, your controller would simply ask the viewport to hide/remove the existing view, and show/add the new view. Calling doLayout() might need to happen as well, depending on your setup.
-
9 Oct 2011 11:23 PM #3
Maybe you can help.
The centerPanel hides but the new panel doesn't show. I'm not sure why this is. Anyone an idea?Code:var master = Ext.ComponentManager.get('idMasterView'); var centerPanel = Ext.ComponentManager.get('idCenterPanel'); var newCenterPanel = Ext.widget('mainCenterTabPanelView'); newCenterPanel.id = 'idCenterPanel'; newCenterPanel.name = 'idCenterPanel'; newCenterPanel.region = 'center'; newCenterPanel.isVisible(true); master.add(newCenterPanel); centerPanel.hide(); newCenterPanel.show(); master.doLayout();
-
10 Oct 2011 1:59 PM #4
I'm guessing you're using a border layout... which doesn't allow you to add/remove children after it's been created.
However, you can add/remove children on the component already existing in the "center" panel. Does that make sense?
In other words, a container with "border" layout might have a panel in it's "center" region. Add/remove children to the panel... not the parent.


Reply With Quote