Results 1 to 5 of 5

Thread: Handler not called for a menu item.

  1. #1
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    102

    Default Handler not called for a menu item.

    I am creating menu from a JSON using this code...
    Code:
    function loadNodes(save,menu){
            for (var i =0; i < save.childNodes.length; i++){
                    var tbi = new Ext.menu.Item({text:save.childNodes[i].name});
                    tbi.handler = clickHandler;
                    menu.add(tbi);
            }
    }
    However, clickHandler isnt called when I click on the item (looking at firebug).
    If I change the item type from Ext.menu.Item to Ext.Button, then the code works fine -except of course that the menu look and behave badly.

    What gives?

  2. #2
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    102

    Default

    Further to the above, working again with firebug, menu onClick is not fired at all.

    If I construct the menu conventionally, eg
    Code:
        toolbar.add({
                text: 'Test menu',
                menu: {
                    xtype: 'menu',
                    plain: true,
                    items: [{
                            text: 'item1',
                            handler: loadHTMLclick
                        },{
                            text: 'item2',
                            handler: loadHTMLclick
                        }]
                   }});
    then the handler is fired.

  3. #3
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    102

    Default

    Yet, more. I laboriously compared properties of the menus in firebug between a manually created one and the code created one. The only difference (apart from names) I could find was that the non-working, code-created version has the menu component with a property "deferLayOut: true". deferLayout property doesnt exist in the hand-created version.

  4. #4
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    102

    Default

    Actually, on close examination, I found another more telling difference.

    Looking at the actual item which has the click handler associated it, I note that in both they have handler:clickHandler in the methods, BUT I look at the events array, I find that in the working one,
    click is an object
    Code:
    click
    Object { name="click",  obj={...},  listeners=} 
    listeners
    [Object { scope={...},  options={...}}] 
    name
    "click" 
    obj
    Object { initialConfig={...},  text="b1",  more...} 
    addListener
    function() 
    clearListeners
    function() 
    createListener
    function() 
    findListener
    function() 
    fire
    function() 
    isListening
    function() 
    removeListener
    function() 
    __proto__
    Object {} 
    deactivate
    true 
    destroy
    true 
    disable
    true 
    enable
    true 
    hide
    true 
    removed
    true 
    render
    true 
    show
    true 
    staterestore
    true 
    statesave
    true
    Whereas in the non-working, code-created version, it simply has click:true.

    What on earth needs to be added to code to make this work?

  5. #5
    Ext JS Premium Member
    Join Date
    Apr 2010
    Posts
    102

    Default [SOLUTION]

    Okay, found the problem. "handler" has to be in the constructor configuration, it isnt a property. Oddly it works for Button though docs dont have handler as a property there either. Anyway, once built into the config options, handler works fine.

Similar Threads

  1. window.open within Ext menu handler, vs called from function
    By smokeman in forum Ext 3.x: Help & Discussion
    Replies: 5
    Last Post: 29 Apr 2010, 7:23 AM
  2. Replies: 6
    Last Post: 20 Aug 2009, 4:19 AM
  3. Menu Item handler...parameters?
    By heidtmare in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 22 Dec 2008, 11:09 AM
  4. add event 'mousedown' handler to Ext.menu.Item
    By mxu in forum Ext 2.x: Help & Discussion
    Replies: 3
    Last Post: 9 Mar 2008, 9:26 PM
  5. context menu item handler on a tree
    By bowa in forum Ext 1.x: Help & Discussion
    Replies: 2
    Last Post: 4 Oct 2007, 6:46 AM

Posting Permissions

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