javascript - 如何在 EXTJS 中仅单击树面板的最后一个子元素时触发事件

标签 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);
        }
    }
}

最佳答案

如果我理解正确,你只需检查节点是否是“叶子”:

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

关于javascript - 如何在 EXTJS 中仅单击树面板的最后一个子元素时触发事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50842769/

相关文章:

javascript - 如何使模型方法在蓝图api中显示

javascript - 如何删除网格面板的标题? - ExtJs

javascript - jQuery 可以与 Ext.js 一起使用吗?

javascript - 使用 JavaScript 或 ExtJS 对格式化字符串数字进行四舍五入

php - 将 Ext Store 数据传递给 php

javascript - 带有空值的 ExtJS JSON 记录

javascript - "Undefined is not a function"错误 jQuery、.replace、scrollTop

javascript - 在 Postman 中的 URL 中传递全局变量

javascript - 在 Jquery 多步骤表单中刷新 Google map

javascript - AngularJS 的 .config()