PDA

View Full Version : remove only child items with autoDestroy=true



dolittle
19 Aug 2009, 2:00 PM
Hi,

I have a panel with several child items.
I want to remove only the items with autoDestroy=true.
I can't iterate the items with ct.items.each and remove them one by one
because I think I'll change the items array while traversing it.
This is the way I do it but there must be a better way:

ct = Ext.getCmp('theContainer');
var items = [];
ct.items.each(function(item, index, l) {
if(item.autoDestroy) {
items.push(item);
}
});
if(items.length > 0) {
Ext.each(items, function(item, index, allItems) {
ct.remove(item, true);
});
}

Thanks

BitPoet
19 Aug 2009, 10:58 PM
What should the second argument to 'remove' do? Ext.util.MixedCollection.remove() takes exactly one argument.
Otherwise, you could always walk the collection backwards by its index:


for( var i = ct.item.getCount() - 1; i >= 0; i-- ) {
if( ct.items.itemAt(i).autoDestroy ) {
ct.removeAt(i);
}
}