English 中文(简体)
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.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签