-
11 Sep 2010 10:50 AM #1
Ext.each(menu.items, myFunction) not working?
Ext.each(menu.items, myFunction) not working?
Hello.
I'm starting with ExtJS. While trying to cycle a split button's items I get undefined errors with:
Ext.each(menu.items, myFunction)
While the following will work fine:
Ext.each(menu.items.items, myFunction)
I don't know if this is by design, or I'm doing something wrong, but I feel there must be a more elegant way of cycling menu items. I don't use menu.items.each(), because I need to recursivelly cycle all buttons/menu items in a toolbar...
So I guess this would be question #2??
Thanks,
Duarte
-
11 Sep 2010 11:26 AM #2Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 40
Read the docs! Ext.each iterates over an Array. Ext.menu.Menu.items is a MixedCollection and not an Array.
For a normal container structure you would use cascade(), but the menuitem/button-menu relation isn't a container-child relation, so that won't work.
-
11 Sep 2010 1:06 PM #3
Condor, hmm that doesn't seem very nice. I'm reading the docs, believe me. It seems that particular nuance eluded me.
I'm not using items.each() since, as I said, I need to recursively access all items in a toolbar.
So I'm doing:
And this does not work, since item is already defined when I reach the last .each call... and that's why I tried Ext.each instead... This is working but I feel this is not correct.Code:toolbar.items.each( function(item) { //operate on this item //then go through its children if(item.menu) item.menu.items.each(arguments.callee(item)); } );
Any more suggestions? Anyone?
Thanks,
Duarte
-
11 Sep 2010 9:45 PM #4
Just declare the fn:
Code:var m, fn = function(item){ // ... if((m = item.menu)){ m.items.each(fn); } }; toolbar.items.each(fn);Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
12 Sep 2010 3:31 AM #5
evant, that is so simple it makes me smile! Works a charm.
Thanks.
Duarte
Similar Threads
-
Ext 2.x to Ext3.0 Ext.menu.Menu duplicate items in diferent menus
By staticduo in forum Ext 3.x: Help & DiscussionReplies: 3Last Post: 26 Mar 2012, 11:54 AM -
[CLOSED] Ext.menu.Menu disable / enable not working
By MrITT in forum Ext 3.x: BugsReplies: 2Last Post: 22 Apr 2010, 1:24 AM -
Reorder/DnD items in a Ext.menu.Menu
By Dr. Flink in forum Ext 2.x: Help & DiscussionReplies: 5Last Post: 16 Feb 2009, 12:35 AM -
Ext.menu.Menu.items.get(i) not working in IE
By nidkil in forum Ext 2.x: Help & DiscussionReplies: 7Last Post: 2 Oct 2008, 2:49 AM -
Ext.menu.Menu.items: How to add a handler to existing items?
By oxi in forum Ext 1.x: Help & DiscussionReplies: 4Last Post: 15 Mar 2007, 10:49 PM


Reply With Quote