Concept:
Consider having two panels A
and B
, and a window C
like in the following example. The buttons on the window switches between the two panels.
var A = new Ext.Panel({
title: 'A'
});
var B = new Ext.Panel({
title: 'B'
});
var C = new Ext.Window({
layout: 'fit',
width: 300,
height: 300,
items: A,
buttons: [
{
text: 'Switch to A',
handler: function() {
C.removeAll(false);
C.add(A);
C.doLayout();
}
}, {
text: 'Switch to B',
handler: function() {
C.removeAll(false);
C.add(B);
C.doLayout();
}
}]
});
C.show();
The concept is very simple: Add a component, remove it and add the same instance again.
Problem: The switch from A to B works, but going back to A doesn't (B stays and A is not shown again).
Question: Thinking OOP, I would expect the above concept to work. Since this is not the case and its a very basic manouvre, how should I think / contemplate / design when I'm trying to do this?
I understand that there might be varying cases when considering a FormPanel vs. other layouts/components - but there must be a general and correct way to do this :)