When doing permissions, the main implementation of the following functions
1, the node can be accessed, then his parent node will also be able to access;
2, the node can be accessed, then his child nodes can also be accessed;
3, the node is inaccessible, and his child nodes are inaccessible.
The use of the number of checkbox with a good user experience, but the difficulty of programming is also a bit increased, if all have a service to complete, that point under the brush, certainly not, can only use Javascript,javascript debugging when depressed very, a word class, And a depressing recursion, trouble.
I used to use the following method
<script language= "JavaScript" >
<!--
//Initialization node
Initchecknode (document.all ("Tvitemclientid"). Value,document.all ("Checked"). Value)
//initialization of selected nodes
function Initchecknode (tree,tvvalue)
{
//Gets the string of nodes that need to initialize the selection state.
var selectednodes = Tvvalue;
var arraynodes = new Array ();
arraynodes = Selectednodes.split (",");
var allrootnode=new Array ();
Allrootnode=document.getelementbyid (tree). GetChildren ();
//initialization of selected nodes
Findandcheckednodes (Allrootnode,arraynodes);
}
//Initializes the selected node based on the string of the selected node
function Findandcheckednodes (nodearray,nodedatas)
{
//alert (nodearray.length);
if (parseint (nodearray.length) ==0)
{
return;
}
Else
{
for (Var i=0;i<parseint (nodearray.length); i++)
{
var cnode,nodedata;
Cnode=nodearray[i];
////If the node is initialized checked = true in Nodedatas;
nodedata = Cnode.getattribute ("Nodedata");
for (var j=0;j<nodedatas.length;j++)
{
if (nodedatas[j] = = nodedata)
{
cnode.setattribute ("Checked", "true");
break;
}
}
//If there are child nodes, continue recursion
if (parseint (Cnode.getchildren (). Length)!=0)
Findandcheckednodes (Cnode.getchildren (), Nodedatas);
}
}
}
//-->
//oncheck Event
function Tree_oncheck (tree)
{
var i;
var node=tree.gettreenode (tree.clickednodeindex);
var pchecked=tree.gettreenode (tree.clickednodeindex). getattribute ("checked");
SetCheck (node,pchecked);
setparent (node,pchecked);
//window.alert (pchecked);
document.all.checked.value = "";
if (Tree.getchildren (). length > 0)
{
for (I=0;i<=tree.getchildren (). length-1;i++)
{
if (Tree.getchildren () [I].getattribute ("Checked"))
{
addchecked (Tree.getchildren () [i]);
}
Findcheckedfromnode (Tree.getchildren () [i]);
}
}
}
//Set child node selected
function SetCheck (node,pchecked)
{
var i;
var childnode=new Array ();
Childnode=node.getchildren ();
if (parseint (childnode.length) ==0)
{
return;
}
Else
{
for (i=0;i<childnode.length;i++)
{
var Cnode;
Cnode=childnode[i];
Cnode.setattribute ("Checked", pchecked);
//cnode.checked = pchecked;
if (parseint (Cnode.getchildren (). Length)!=0)
{
SetCheck (cnode,pchecked);
}
}
}
}
//Set child node selected/canceled;
//At the same time you need to set the state of the parent node (if it is unchecked, just set this node and all of its word contacts, not the parent contact)
function SetParent (node,pc)
{
var parentnode = node.getparent ();
if (parentnode)
{
var parentnodefather = parentnode.getparent ();
if (parentnodefather)
{
setparent (PARENTNODE,PC);
}
if (Pc)
{parentnode.setattribute ("checked", Pc);}
Else
{
Checkbrother (Parentnode,pc,node.getattribute ("Nodedata"))
}
}
}
//Check whether the child contact has a choice, if there is a choice, that returns True
//Check only the first level node.
function Checkbrother (parentnode,pc,nodedata)
{
var childnodes = new Array ();
childnodes = Parentnode.getchildren ();
if (childnodes.length >0)
{
var bchecked = true;
for (var i=0;i<childnodes.length;i++)
{
if (Childnodes[i].getattribute ("checked") = = True && childnodes[i].getattribute ("Nodedata")!= Nodedat A)
{
//alert (I+childnodes[i].getattribute ("Text"));
bchecked = false;
break;
}
}
if (bchecked)
{
parentnode.setattribute ("checked", Pc);
}
Else
{
//All parent node selection
SetParent (parentnode,! PC)
}
}
Else
{
parentnode.setattribute ("checked", Pc);
}
}
//Get all node status
function Findcheckedfromnode (node)
{
var i = 0;
var nodes = new Array ();
nodes = Node.getchildren ();
for (i = 0; I <= nodes.length-1; i++)
{
if (Nodes[i].getattribute ("Checked"))
{
addchecked (Nodes[i]);
}
if (parseint (Nodes[i].getchildren (). Length)!= 0)
{
Findcheckedfromnode (Nodes[i]);
}
}
}
//Add selected node
function addchecked (node)
{
Document.all.checked.value + = Node.getattribute ("nodedata") + ",";
}
//-->