PDA

View Full Version : Reuse same instance



Alexander Bauer
12 Aug 2012, 2:49 AM
Hi,

I have a custom layout. The base panel has a border layout. It consists of a west panel (menu) a north tabbar (height : 25, the tabbar is the only visible one) and a center panel, which always replaces its contents using .removeAll(); and .add(cmp);

I need this layout because I want to be the tabbar above the west & center regions, not only the center region but the tab content should be in the center panel. Now when you click on a tab, it uses the activate event and puts its items property into the center panel.

While this works fine so far, I have issues reusing same components. A tab consists of a form and when you edit the form, switch to another tab or a menu button I have to remove it from the center panel (removeAll()) and when you select the tab again I need to add the center panel.



var tab = Ext.create('Ext.panel.Panel', {
closable : true,
title : ''
record : record,
listeners : {
activate : function() {
this.myRequest = Ext.create('myPanel', {
record : record,
myTab : this
});
centerPanel.setItem(this.myRequest);
}
}
});



When I save the panel for reusing like :


if(!this.myRequest) {
this.myRequest = Ext.create('myPanel', {
record : record,
myTab : this
});
}
centerPanel.setItem(this.myRequest);


I cant get it render again. If I use Ext.create() or xtype, the changes of form fields will be lost, since its a new instance.

So the question is: is there a way to reuse the same instance multiple times after .add() and .remove() ?

I attached a screenshot how my layout should look like.
37883

Alexander Bauer
12 Aug 2012, 3:34 AM
ok, nevermind... how stupid.
just had to add : removeAll(false); to prevent the components from being destroyed.

SebTardif
12 Aug 2012, 4:27 AM
You should mark your question answered.

nothing
12 Nov 2012, 8:38 AM
Thanks man. removeAll(false); was the solution I was looking for 2 days now...........................