1. #1
    Sencha User
    Join Date
    Sep 2010
    Posts
    7
    Vote Rating
    0
    dncpax is on a distinguished road

      0  

    Default 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

  2. #2
    Sencha - Community Support Team Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    94
    Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of Condor has much to be proud of

      -1  

    Default


    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.

  3. #3
    Sencha User
    Join Date
    Sep 2010
    Posts
    7
    Vote Rating
    0
    dncpax is on a distinguished road

      0  

    Default


    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:
    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));
      }
    );
    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.

    Any more suggestions? Anyone?

    Thanks,
    Duarte

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    17,004
    Vote Rating
    650
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    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!

  5. #5
    Sencha User
    Join Date
    Sep 2010
    Posts
    7
    Vote Rating
    0
    dncpax is on a distinguished road

      0  

    Default


    evant, that is so simple it makes me smile! Works a charm.

    Thanks.
    Duarte

Similar Threads

  1. Ext 2.x to Ext3.0 Ext.menu.Menu duplicate items in diferent menus
    By staticduo in forum Ext 3.x: Help & Discussion
    Replies: 3
    Last Post: 26 Mar 2012, 11:54 AM
  2. [CLOSED] Ext.menu.Menu disable / enable not working
    By MrITT in forum Ext 3.x: Bugs
    Replies: 2
    Last Post: 22 Apr 2010, 1:24 AM
  3. Reorder/DnD items in a Ext.menu.Menu
    By Dr. Flink in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 16 Feb 2009, 12:35 AM
  4. Ext.menu.Menu.items.get(i) not working in IE
    By nidkil in forum Ext 2.x: Help & Discussion
    Replies: 7
    Last Post: 2 Oct 2008, 2:49 AM
  5. Ext.menu.Menu.items: How to add a handler to existing items?
    By oxi in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 15 Mar 2007, 10:49 PM

Thread Participants: 2

Tags for this Thread