In the code below, everytime you click the Add Item button in the left panel, all buttons are removed from the center panel and new buttons are added (one more than existed previously). They all get the same flex value, but they don't become the same size. Debugging shows that for button's with an id that existed before, the flex value is retrieved from the state with that id. I presumed that the state would be destroyed with the button upon removal...
Code:
Ext.application({ name: 'JSTest', launch: function () { Ext.create('Ext.container.Viewport', { layout: 'border', items: [ { xtype: 'panel', region: 'north', html: '<h1>JavaScript Test</h1>' }, { xtype: 'panel', region: 'west', title: 'Left Panel', layout: 'absolute', split: true, width: 300, items: [ { xtype: 'button', x: 10, y: 10, text: 'Add item', handler: function () { var p = Ext.getCmp('p'); var n = p.items.length + 1; p.removeAll(true); for (var i = 1; i <= n; i++) { p.add(Ext.create('Ext.button.Button', { xtype: 'panel', border: true, flex: 1000 / n, id: 'p' + i.toString(), text: 'p' + i.toString() })); } } }, { xtype: 'button', x: 10, y: 50, text: 'Clear', handler: function () { var p = Ext.getCmp('p'); p.removeAll(true); } } ] }, { id: 'p', xtype: 'panel', region: 'center', title: 'Center Panel', layout: { type: 'vbox', align: 'stretch' } } ] }); }});