-
18 Apr 2009 5:34 AM #1
[FIXED][3.0] Ext.Container.removeAll() results in infinite loop
[FIXED][3.0] Ext.Container.removeAll() results in infinite loop
What steps will reproduce the problem?
Create a container and add various components to it. Now add a "beforeremove" listener to the container and return for at least one component "false", which basically tells the container to not remove this component. Now call "removeAll()" on the container.
What is the expected output?
All components except for the one where the "beforeremove" listener returned "false" get removed from the container.
What do you see instead?
The "removeAll()" gets stuck in an infinite loop, due to
The condition for the while loop will always equal to true, since "this.items.last()" will reference the component for which the "beforeremove" listener returned "false".PHP Code:removeAll: function(autoDestroy){
this.initItems();
var item, items = [];
while((item = this.items.last())){
items.unshift(this.remove(item, autoDestroy));
}
return items;
},
-
20 Apr 2009 9:13 AM #2
Fair enough, try the following patch + test case:
Code:Ext.override(Ext.Container, { removeAll: function(autoDestroy){ this.initItems(); var item, rem = [], items = []; this.items.each(function(i){ rem.push(i) }); for (var i = 0, len = rem.length; i < len; ++i){ item = rem[i]; this.remove(item, autoDestroy); if(item.ownerCt !== this){ items.push(item); } } return items; } });Code:Ext.onReady(function(){ var tabs = new Ext.TabPanel({ width: 400, height: 400, renderTo: document.body, items: [{ title: 'Item 1' },{ title: 'Item 2' },{ title: 'Item 3' },{ title: 'Item 4' }], listeners: { beforeremove: function(ct, c){ return c.title != 'Item 2'; } } }); console.log(tabs.removeAll()); });Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
Thank you for reporting this bug. We will make it our priority to review this report.



Reply With Quote