处理树面板 Extjs 4 上的 itemclick 事件 [英] Handling itemclick event on tree panel Extjs 4

查看:25
本文介绍了处理树面板 Extjs 4 上的 itemclick 事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是在不同的树叶点击上得到不同的反应!

what I am trying to do is to get different reaction on a different tree LEAF click!

var myTree = Ext.create('Ext.tree.Panel',
    store: store,
    rootVisible: false,   
    border: false,
    listeners: {
        itemclick: function(index) {            
            var record = store.getAt(index);
            alert(record);          
        }
    }
});

我尝试使用索引来获取叶子的索引,什么也没有.我可以在节点点击时获得反应,但如何在每片叶子上获得特定反应?我也试过给叶子提供 ID,没有运气???

I tried with index, to get the index of leaf, nothing. I can get a reaction on a node click, but how to get a specific reaction on every leaf? I also tried giving ID to the leafs, no luck???

也许是一个简单的例子

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

}

请帮忙!!

推荐答案

itemclick 事件侦听器的函数参数index"未指向树节点的索引.就像您在问题末尾提到的那样,itemclick 事件的语法是:

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) {

}

这是一个例子:

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},

这篇关于处理树面板 Extjs 4 上的 itemclick 事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆