Results 1 to 6 of 6

Thread: Event handling for menu in extjs 4

  1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    3
    Vote Rating
    0
      0  

    Default Answered: Event handling for menu in extjs 4

    Hi

    We are using Extjs 4 for our application development. We are trying to implement dynamic controller loading. (http://www.sencha.com/forum/showthre...MVC-controller) For this to work we need to have the menu's selection events captured in our controller. In our current design we are using the 'handler' to capture the menu click event. But we would want to change the design to have a view where we define our menu details, the selection event menu items need to be captured with in the controller. Any tips/ suggestion will of great help. Thanks in advance.

    Currently our implementation is
    Ext.define('App.view.layout.AppMenu', {
    extend : 'Ext.menu.Menu',
    alias : 'widget.AppMenu',
    layout : 'fit',
    plain : true,
    floating : false, // usually you want this set to True (default)
    renderTo : Ext.getBody(), // usually rendered by it's containing component
    items : [ {
    text : 'Users',
    handler : onItemClick,
    iconCls : 'user_info_icon',
    }, {
    text : 'Managers'

    }

    });


    function onItemClick() {
    // steps based on the menu items selected...
    }

  2. So you have a controller for your app that could listen for menu's events now, correct?
    If so, you should be able to add a listener for the menuItem's click event and place your logic in a function there.
    http://docs.sencha.com/ext-js/4-0/#/api/Ext.app.Controller-method-control

    Code:
    E
    Code:
    xt.define('App.controller.MainAppController', {
        init: function () {
            this.control ({
                'AppMenu > menuitem': {
                    click: this.onAppMenuClick
                }
            })
        }
        , onAppMenuClick: function (menuitem, e, opt) {
            // steps based on the menu items selected...
        }
    })

  3. #2
    Sencha - Documentation Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,162
    Answers
    501
    Vote Rating
    257
      0  

    Default

    So you have a controller for your app that could listen for menu's events now, correct?
    If so, you should be able to add a listener for the menuItem's click event and place your logic in a function there.
    http://docs.sencha.com/ext-js/4-0/#/api/Ext.app.Controller-method-control

    Code:
    E
    Code:
    xt.define('App.controller.MainAppController', {
        init: function () {
            this.control ({
                'AppMenu > menuitem': {
                    click: this.onAppMenuClick
                }
            })
        }
        , onAppMenuClick: function (menuitem, e, opt) {
            // steps based on the menu items selected...
        }
    })

  4. #3
    Sencha User
    Join Date
    Aug 2011
    Posts
    3
    Vote Rating
    0
      0  

    Default

    Appreciate your quick response! I was able to capture the click event but I'm not able to get the selected item text. I get menuitem as undefined in "onAppMenuClick" function. Not sure if I'm missing something here.

  5. #4
    Sencha User jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    DC Area =)
    Posts
    16,364
    Answers
    102
    Vote Rating
    86
      0  

    Default

    You should listen to the menu's click event, not the item:

    click( Ext.menu.Menu menu, Ext.Component item, Ext.EventObject e, Object options )

  6. #5
    Sencha User
    Join Date
    Aug 2011
    Posts
    3
    Vote Rating
    0
      0  

    Default

    I added the following code. Now I'm able to handle the click event and also I'm able to get the selected menu text.

    Code:
    init : function(application) {
                    
                    this.control({
                        'AppMenu > menuitem' : {
                            click : this.onItemClick
                        }
                    });
                },
    
    onItemClick:function(menuitem){
        switch (menuitem.text) {
    // logic is added here
         }
    }
    Thanks all for the inputs

  7. #6
    Sencha User
    Join Date
    May 2011
    Posts
    70
    Answers
    4
    Vote Rating
    0
      0  

    Default

    thanks for answers here - saved me too

    The selector can also include the menu item id - maybe split out actions without the switch
    eg. 'menu > menuitem#refresh'

    thx

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •