DaveC426913
26 Nov 2010, 2:36 PM
I want to delete items from my list only if they're checked.
Unfortunately, the Ext.each loop does not seem to be smart enough to know that my list is getting shorter. So by the time it gets to the end, it is trying to delete more items than currently exist.
Here is the code snippet:
lineItems = Ext.getCmp("myList_textpanel").items.items;
Ext.each(lineItems, function(o){
var objIsChecked = o.items.items[0].checked;
var objText = o.items.items[1].text
console.log('checking ' + objText)
if (objIsChecked){
console.log('DELETING ' + objText)
lineItems.remove(o);
}
});
So I check B, then click 'Clear Checked'. Here's the output:
checking A
checking B
DELETING B
checking D
checking E
checking F
checking G
checking H
Uncaught TypeError: Cannot read property 'items' of undefined
Notice that C is missing. Not only has it skipped over C, but when it gets to the end of the list, it finds itself one short. I was under the impression that a 'For each' operates ON the object, not on a prebuilt reference to where the object was.
(Maybe I can go through the list in reverse order?)
Unfortunately, the Ext.each loop does not seem to be smart enough to know that my list is getting shorter. So by the time it gets to the end, it is trying to delete more items than currently exist.
Here is the code snippet:
lineItems = Ext.getCmp("myList_textpanel").items.items;
Ext.each(lineItems, function(o){
var objIsChecked = o.items.items[0].checked;
var objText = o.items.items[1].text
console.log('checking ' + objText)
if (objIsChecked){
console.log('DELETING ' + objText)
lineItems.remove(o);
}
});
So I check B, then click 'Clear Checked'. Here's the output:
checking A
checking B
DELETING B
checking D
checking E
checking F
checking G
checking H
Uncaught TypeError: Cannot read property 'items' of undefined
Notice that C is missing. Not only has it skipped over C, but when it gets to the end of the list, it finds itself one short. I was under the impression that a 'For each' operates ON the object, not on a prebuilt reference to where the object was.
(Maybe I can go through the list in reverse order?)