1. #1
    Ext User
    Join Date
    Mar 2007
    Posts
    31
    Vote Rating
    0
    oxi is on a distinguished road

      0  

    Default Ext.menu.Menu.items: How to add a handler to existing items?

    Ext.menu.Menu.items: How to add a handler to existing items?


    I managed to feed a Menu with JSON data. Now I want to add a handler to each Menu Item. I tried many things but I never had any success:

    Code:
    ...
    var menuC = new Ext.menu.Menu({
            id: 'mainMenu',
            items: Ext.decode(responseText)
    });
    
    menuC.items.get(1).handler = 'function(arg){alert();}';
    menuC.items.get(1).on("click", menuC.items.get(1).target, menuC.items.get(1).scope, true);
    ...
    Acutally I want to achieve that the same function is called by each item with the according item id as argument.

    Please Help

  2. #2
    Ext User
    Join Date
    Mar 2007
    Posts
    31
    Vote Rating
    0
    oxi is on a distinguished road

      0  

    Default


    After hours of trying the solution was that simple:

    Code:
    menuC.on('click', function(menu, item){
        alert('Item "' + item.id + '" at Menu: ' + menu.id + ' was clicked.');
    });

  3. #3
    Ext JS Premium Member mikegiddens's Avatar
    Join Date
    Mar 2007
    Location
    Denver, Colorado
    Posts
    273
    Vote Rating
    1
    mikegiddens will become famous soon enough

      0  

    Default


    oxi,

    I am looking to do a json linked menu just like you are doing and could use some guidence on how the response text looked like from the jsondata. Or how you made the request to the data. Any code on that would be a great help and save me a few hours of banging my head.

    At first I was tring to do a no toolbar menu like:



    http://www.herbarium.lsu.edu/advancedimagesearch.php (Old YUI Concept)

    This was done with YUI a long time back but now tring to replicate this feature somehow in a Ext version. I might end up in a toolbar if anyone has an idea of how to pull this off any direction would be great.

  4. #4
    Sencha - Ext JS Dev Team Animal's Avatar
    Join Date
    Mar 2007
    Location
    Notts/Redwood City
    Posts
    30,546
    Vote Rating
    64
    Animal is a jewel in the rough Animal is a jewel in the rough Animal is a jewel in the rough

      0  

    Default


    A menu bar example here: http://www.yui-ext.com/forum/viewtop...start=15#15763

    Jack is going to adopt it in a future version of Ext, so look for an improved version to be available soon. The interface souldn't change too much though, you should be able to accommodate any changes easily.

  5. #5
    Ext JS Premium Member mikegiddens's Avatar
    Join Date
    Mar 2007
    Location
    Denver, Colorado
    Posts
    273
    Vote Rating
    1
    mikegiddens will become famous soon enough

      0  

    Default


    Thanks animal for the update. I looked at that post but it is too late to wrap my mind around anything.

    I did give oxi idea some thought and this is what I came up with. There may be a better way to generate a menu from server data onthe fly but this works for me for now.

    Code:
    								//----------------------------------------------------------
    								// Create Menu for Image Filter
    								// Sample Response Text  = "[{text: 'Item 1'},{text: 'Item2',menu: { items: [{text: 'Sub 1'}]	}}]"								
    								//----------------------------------------------------------
    
    								Ext.get('images-cp').createChild({tag:'div',id:'images-menubar'});
    
    								var menuSuccess = function(o){
    									if(o.responseText){
    										var menu = new Ext.menu.Menu({
    												id: 'mainMenu',
    												items: Ext.decode(o.responseText)
    										});
    		
    										var tb = new Ext.Toolbar('images-menubar');
    										tb.add({
    												cls: 'x-btn-text', // icon and text class
    												text:'Image Filter',
    												menu: menu
    										});
    									}
    								}
    
    								YAHOO.util.Connect.asyncRequest('GET', 'util/get-filter-menu.php', {success: menuSuccess});          
    								//----------------------------------------------------------
    I hope this might help someone or if anyone sees a betterway to improve my thinking using a json store or something great. now I need some sleeeeeppp.....

Similar Threads

  1. Dragging Tree Items over iFrames
    By cogitatio in forum Ext 1.x: Help & Discussion
    Replies: 3
    Last Post: 30 Dec 2008, 12:04 PM
  2. How to add right click menu to selected items in grid?
    By KRavEN in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 13 Sep 2007, 2:30 AM
  3. IE6 Nonsecure items message for SSL
    By vtswingkid in forum Ext 2.x: Help & Discussion
    Replies: 11
    Last Post: 10 Jul 2007, 2:05 AM
  4. Right-aligned items in the toolbar
    By soad in forum Ext 1.x: Help & Discussion
    Replies: 5
    Last Post: 2 Apr 2007, 5:25 AM
  5. Focus left on menu items
    By KimH in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 22 Feb 2007, 4:20 PM

Thread Participants: 2