1. #1
    Sencha User
    Join Date
    Aug 2011
    Posts
    3
    Vote Rating
    0
    rvini2006 is on a distinguished road

      0  

    Default Answered: Event handling for menu in extjs 4

    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 - Support Team slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    4,913
    Answers
    371
    Vote Rating
    179
    slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold slemmon is a splendid one to behold

      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
    rvini2006 is on a distinguished road

      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
    jay@moduscreate.com's Avatar
    Join Date
    Mar 2007
    Location
    Frederick MD, NYC, DC
    Posts
    16,353
    Answers
    102
    Vote Rating
    79
    jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all jay@moduscreate.com is a name known to all

      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
    rvini2006 is on a distinguished road

      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
    gnube is on a distinguished road

      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

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi