ExtJS as shown, implement a tree with a check box, select all child nodes when the parent node is selected. The root node can be canceled when all child nodes are canceled.
Copy Code code 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: ' Hint ',
Msg: ' Server busy, please use Firefox browser or try again later! ',
Buttons:Ext.MessageBox.OK,
Icon:Ext.MessageBox.ERROR
});
}
});
}