extjs 如图,实现带有复选框的树/选中父节点时,选中所有子节点。取消所有子节点时,才能取消根节点。

Home >Web Front-end >JS Tutorial >About the problem of selecting parent node and child node in extjs treepanel checkbox_extjs

About the problem of selecting parent node and child node in extjs treepanel checkbox_extjs

WBOY
WBOYOriginal
2016-05-16 17:38:241108browse
About the problem of selecting parent node and child node in extjs treepanel checkbox_extjs
extjs As shown in the figure, implement a tree with check boxes. When the parent node is selected, all child nodes are selected. The root node can only be canceled when all child nodes are canceled.
Copy code The code is as follows:

var Fpanel = new Ext.tree.TreePanel({
id:'ptree',
region:'west',
layout:'anchor',
border:false,
rootVisible: false,
root:new Ext.tree. AsyncTreeNode({}),
listeners:{
"checkchange": function(node, state) {
if (node.parentNode != null) {
//Child node selected
node.cascade(function(node){
node.attributes.checked = state;
node.ui.checkbox.checked = state;
return true;
});
// Parent node selected
var pNode = node.parentNode;
if (state || Fpanel.getChecked(id, pNode) == "") {
pNode.ui.toggleCheck(state);
pNode.attributes.checked = state;
}
}
}
}
});
authorityTree(Fpanel);
var authorityTree = function(Fpanel){
Ext.Ajax.request({
url: 'authorityTree.ashx',
method:'get',
success: function(request) {
var data = Ext.util.JSON .decode(request.responseText);
Fpanel.getRootNode().appendChild(data);
Fpanel.getRootNode().expandChildNodes(true);
Fpanel.expandAll();
},
failure: function() {
Fpanel.render();
Ext.MessageBox.show({
title: 'Prompt',
msg: 'The server is busy, please use Firefox to browse Browse with your browser or try again later! ',
buttons: Ext.MessageBox.OK,
icon: Ext.MessageBox.ERROR
});
}
});
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn