我正在使用 ExtJs 树面板。当您选择该节点时,是否有任何内置方法或属性会取消选择该节点的所有子节点。
所以考虑下图,假设黄色背景的节点已经被选中。如果我现在选择 1.1,系统应该自动取消选择 1.1.2,如果我选择节点 1,它应该取消选择 1.1.2、.1.2.1、1.2.2。
请提供您的建议
Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
renderTo: Ext.getBody(),
width: 400,
height: 400,
store: {
root: {
expanded: true,
children: [{
text: "1 detention",
expanded: true,
"checked": false,
children: [{
text: '1.1 foo',
leaf: true,
"checked": false
}, {
text: '1.2 bar',
leaf: true,
"checked": false
}]
}, {
text: "2 homework",
expanded: true,
"checked": false,
children: [{
text: "2.1 book report",
leaf: true,
"checked": false
}, {
text: "2.2 algebra",
expanded: true,
"checked": false,
children: [{
text: "2.2.1 buy lottery tickets",
leaf: true,
"checked": false
}, {
text: "2.2.2 buy lottery tickets 2",
leaf: true,
"checked": false
}]
}]
}, {
text: "3 buy lottery tickets",
leaf: true,
"checked": false
}]
}
},
useArrows: false,
rootVisible: false,
selModel: {
mode: 'SIMPLE'
},
listeners: {
deselect: function (tree, record) {
if (record.data.text === '1 detention') {
}
},
select: function (tree, record) {
var parentNode = record.parentNode;
// Deselect children
function deselectChildren(record) {
tree.deselect(record.childNodes, false);
record.eachChild(deselectChildren);
}
deselectChildren(record);
// See if all siblings are selected now
var allSiblingSelected = false;
if (parentNode) {
allSiblingSelected = parentNode.childNodes.reduce(function (previous, node) {
return previous && tree.isSelected(node)
}, true);
}
if (allSiblingSelected) {
tree.select(parentNode, true); // will trigger req 1
}
// Deselect ancestors
else {
while (parentNode) {
tree.deselect(parentNode);
parentNode = parentNode.parentNode;
}
}
}
}
});