我有树面板。我想在仅单击子元素时触发事件。
在我的 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/