如何在EXTJS中仅单击treepanel的last子元素时触发事件

时间:2018-06-13 17:10:25

标签: javascript extjs

我有树梢。我想点击唯一的子元素来发起一个事件。

在我的itemclick事件中,当我点击时,它一直在触发。我只想在点击最后一个孩子时才开火。

例如:它应该激活“管理应用程序子”而不是“管理应用程序”

var root = {
    expanded: true,
    children: [{
        text: "Configure Application",
        expanded: true,
        children: [{
            text: "Manage Application",
            children: [{
                text: "Manage Application Child",
                leaf: true
            }]
        }, {
            text: "Scenario",
            leaf: true
        }]
    }, {
        text: "User Configuration",
        expanded: true,
        children: []
    }, {
        text: "Test Configuration",
        //leaf: true,
        expanded: true,
        children: [{
            text: "Manage User",
            leaf: true
        }, {
            text: "User rights",
            leaf: true
        }]
    }]
};

{
    xtype: 'treepanel',
    useArrows: true,
    autoScroll: false,
    animate: true,
    enableDD: false,
    title: 'Configuration',
    width: 200,
    height: 400,
    rootVisible: false,
    store: Ext.create('Ext.data.TreeStore', {
        root: root
    }),
    listeners: {
        itemclick: function (s, r) {
            alert(r.data.text);
        }
    }
}

2 个答案:

答案 0 :(得分:3)

如果我理解正确,你只需检查节点是否是" leaf":

           itemclick: function (s, r) {
                if (r.data.leaf){ //or r.data.children == null
                    alert(r.data.text);
                }                 
            }

答案 1 :(得分:0)

我创建FIDDLE我认为它会帮助你想要的东西