开发者

TreeNode click event on ExtJs 4

I'm using ExtJS 4 (beta 3) and I have a TreePanel that is my kind of navigation menu. It is something like this:

  • Jobs
    • Add Job
    • List All Jobs
  • ...
    • ...
    • ...

(this will be made on a permission system base, but that's another story)

On ExtJS 3, do something when i clicked "Add Job" was as simple as adding

...
leaf:true,
listeners:{
click:function(n){
       //my code...
   }
}
...

to the root children elements.

Now It's not that simple. The closer i got was with (on the treepanel)

listeners:{
    click : {
             element : 'el',
             fn : function(eve, elem, obj){
                   console.log(node);
                   console.log(elem);
                   console.log(obj);
                  }
    }
}

So, maybe i'm just a noob, maybe i have already a strong hatred for ExtJS, maybe is just a problem in this beta version, but...

How do I add a listener to the click event on the tree nodes? (the Select event won't do what i need)

Thank you guys.

EDIT: Currently testing with this, and it's not working.

 ... = Ext.create('Ext.tree.TreePanel', {
                        region      : 'west',
                        collapsible : false,
                        title       : 'ITMI',
                        width       : 220,
                        margins     : '5 5 5 5',
                        cmargins    : '5 5 5 5开发者_开发百科',
                        hideHeaders : true,
                        useArrows   : true,
                        rootVisible : false,
                        headers: [{
                                xtype    : 'treeheader',
                                text     : 'Nome',
                                flex     : 1,
                                dataIndex: 'nome'
                            }],
                        store: store,
                        listeners:{
                            itemclick: function(n){
                                console.info(n);
                            }
                        }
    ...

EDIT 2: The itemclick event now works (on EXJS 4 final), It still doesn't solve my problem. I'd Like to call a specific function when i call each treenode. Before it was really easy. Now i can't figure it out.


in ext4 beta3 (maybe in final release too)... there is no longer click event....
this has changed to itemclick more info

var tree = Ext.create('Ext.tree.Panel', {
    store: store,
    renderTo: Ext.getBody(),
    height: 300,
    width: 250,
    title: 'Files',

    listeners:{
        itemclick: function(n){
            console.info(n);
        }
    }

});


So, It may help some people who may be struggling with the same issue I did then.

The "itemclick" event is the way to handle leafs clicks, and it didn't work then for reasons I don't remember.

I accomplished what I needed by splitting the config I had in the database, something like

controllerName|functionName

and then call this code on the handler of the "itemclick:

this.getController(ctr)[fn]();  

where ctr is the controllerName and fn is the functionName. This could easily be done with eval, but I prefer not to.


I could not get itemclick to fire with IE (fine in Chrome). I modified my code to use 'checkchange' and it works fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜