Results 1 to 8 of 8

Thread: How to capture AsyncTreeNode click events

  1. #1
    Sencha User
    Join Date
    Mar 2010
    Posts
    19

    Default How to capture AsyncTreeNode click events

    I'm sure this has been beaten to death, but can someone point me at a small example of a TreePanel that captures click and right-click events on AsyncTreeNodes?

    Here's my treePanel, but I'm not sure how to properly add the listeners.

    Code:
    var tree = new Ext.tree.TreePanel({
        loader: new Ext.tree.TreeLoader(),
            useArrows: true,
            autoScroll: true,
            animate: true,
            enableDD: true,
            containerScroll: true,
            border: false,
    
        root: new Ext.tree.AsyncTreeNode({
            expanded: true,
            leaf: false,
            text: 'My Tree',
            children: children
        }) /* ,
        listeners: {
            click: {
                fn: clickListener
            }
        }
        */
    });

  2. #2
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    And what's wrong with what you have?

    I mean apart from you are listening for left click instead of contextmenu?

  3. #3
    Sencha User
    Join Date
    Mar 2010
    Posts
    19

    Default

    And what's wrong with what you have?
    The code in the initial post shows the listeners section commented out. If I uncomment that, and include the callback below, my JS doesn't load in the browser.

    Code:
    clickListener = function (node, evnt) {
        // The node argument represents the node that
        // was clicked on within your TreePanel
    };
    I mean apart from you are listening for left click instead of contextmenu?
    Initially I was just trying to get a left-click event there. I was going to add right-click when the left-click was working.

    -Robot

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    "doesn't load"?

    What's that supposed to mean? You get a syntax error somewhere?

  5. #5
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676

    Default

    you should learn to deal with js errors and work with a js console/debugger

    i guess clickListener is out of scope. Try simple first

    Code:
    listeners: {
            click: function(node) {
                alert(node.attributes.id);
            }
        }
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

  6. #6
    Sencha User
    Join Date
    Mar 2010
    Posts
    19

    Default

    "doesn't load"? What's that supposed to mean?
    Viewport doesn't display (blank screen). When I comment out the code, the app displays properly.

    You get a syntax error somewhere?
    Actually, no syntax error reported in NetBeans, but I figured out the problem: a missing var keyword in front of the callback definition.

    Another problem was my callback definition was after the reference. Once I added var and moved the definition prior to the reference, it worked.

    Thank you for taking a look.

    -Robot

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,892

    Default

    NetBeans? Never heard of that browser.

  8. #8
    Sencha Premium Member steffenk's Avatar
    Join Date
    Jul 2007
    Location
    Haan, Germany
    Posts
    2,676

    Default

    Netbeans is a php IDE. (and Java i think)

    You have to look in browser for Javascript errors, IDE only shows some syntax errors, but can't resolve object errors.

    Start simple with alert or console.log in click listener. i guess your function is out of scope.
    vg Steffen
    --------------------------------------
    Release Manager of TYPO3 4.5

Posting Permissions

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