Handling itemclick event on tree panel Extjs 4

耗尽温柔 提交于 2019-11-30 05:34:44

The itemclick event listener's function param "index" does not point to your tree node's index. Like you mentioned in end of your question the syntax for the itemclick event is:

function(Ext.view.View this, Ext.data.Model record, HTMLElement item, Number index, Ext.EventObject e) {

}

Here is an example:

itemclick : function(view,rec,item,index,eventObj) {

    // You can access your node information using the record object
    // For example: record.get('id') or record.get('some-param')
    if(r.get('id')=='SP') {
        // I do my necessary logic here.. may be open a perticular window, grid etc..
    }

    if(r.get('id')=='CO') {
        // I do my necessary logic here.. may be open a perticular window, grid etc..
    }           
}

And here is an example of my tree node's data:

{ text: 'SP Reports', id: 'SP', leaf: true},
{ text: 'CO Reports', id: 'CO', leaf: true},

Itemclick handler already gives you everyting you need:

itemclick(view, record, item, index, e ) {
    var id = record.get('id');
    // do something depending on the record data.
    // console.log(record);
}

I was trying to do a generic treepanel's item click handler and to be able to get a custom field I added to the node object. This helped me out. I dunno if this is the standard and compatible ExtJs 4 way:

            (Some Panels Here),
            items: [{
                xtype: 'treepanel',
                listeners: {
                    itemclick: {

                        fn: function (view, record, item, index, e) {

                            console.log(record.raw.userData);
                        }
            (removed...)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!