-
26 Nov 2010 2:36 PM #1
Ext.each : with remove - not smart enough
Ext.each : with remove - not smart enough
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:
So I check B, then click 'Clear Checked'. Here's the output:Code: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); } });
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?)
-
26 Nov 2010 2:54 PM #2
OK, well since Sencha can't do it, at least the usual decrementing loop doesn't throw an error.
Now I've just got to figure out why it won't refresh the screen with doLayout(). Actually, it's quite strange - when I examine the objects, the items are gone, but their keys are not. Even stranger, if I then click my 'Delete All' button, all items are removed from the list EXCEPT the ones that were checked - as if those removed items are now 'ghosts' that can't be killed.
Code:lineItems = Ext.getCmp("myList_textpanel").items.items; for (var item=lineItems.length-1; item>=0; item-- ){ lineItem = lineItems[item]; var objIsChecked = lineItem.items.items[0].checked; var objText = lineItem.items.items[1].text console.log('checking ' + objText) if (objIsChecked){ console.log('DELETING ' + objText) lineItems.remove(lineItem); } } Ext.getCmp("myList_textpanel").doLayout();
-
26 Nov 2010 10:57 PM #3
Hi,
I also tried to remove dom elemenets underlying my Main panel.
Similar to you i also iterated in reverse order. Now it works.
-
27 Nov 2010 12:40 AM #4
Seriously? You are simply removing items from a memory array that is used and managed within a MixedCollection object which is used within a Container object, and you are hoping that it will automagically update all the internal structures which reference that array?
Container.remove???Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
29 Nov 2010 6:50 AM #5
-
30 Nov 2010 10:36 AM #6
OK. Got it.
lineItem.destroy();
Thanks everyone who helped me.
Similar Threads
-
Smart Ext.util.Format.ellipsis ??
By chalu in forum Ext 2.x: Help & DiscussionReplies: 1Last Post: 7 Feb 2011, 11:42 PM -
Is smart rendering possible in grid???
By jeff77 in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 10 Sep 2010, 12:03 AM -
Recommendations for handling MS Word Smart Quotes in Ext
By mrileyaz in forum Ext 3.x: Help & DiscussionReplies: 0Last Post: 1 Jun 2010, 2:31 PM -
Smart Ext toolbar
By tinnt in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 20 Nov 2008, 7:04 PM


Reply With Quote