The complete code is pasted below, and I have taken a lot of detours, because I read the code from my friends in the reply. Now I don't have to bother with it.
Copy codeThe Code is as follows:
<Script src = "js/jquery-1.4.2.min.js" type = "text/javascript"> </script>
<Script src = "js/jquery. mytree. js" type = "text/javascript"> </script>
<Link href = "second.css" rel = "stylesheet" type = "text/css"/>
<Script type = "text/javascript">
$ (Function (){
Var o = {showcheck: true };
O. data = <% = treeNodes %>;
$ ("# Tree"). treeview (o );
})
</Script>
Background
Copy codeThe Code is as follows:
Public string GetFirJson ()
{
String mystr = "[";
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where parientid = 0 ");
Int a = dt. Rows. Count;
For (int I = 0; I <= dt. Rows. Count-1; I ++)
{
Mystr + = GetOtherJson (Convert. ToInt32 (dt. Rows [I] ["classid"]. ToString () + ",";
}
Mystr = mystr. Substring (0, mystr. Length-1 );
Mystr + = "]";
Mystr = mystr. Replace ("'","\"");
Return mystr;
}
// Recursion
Private string GetOtherJson (int pid)
{
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where classid =" + pid );
String strjson = "";
Bool haschild = IsHasChild (pid );
Strjson = "{";
Strjson + = "'id': '" + pid + "',";
Strjson + = "'text': '" + dt. Rows [0] ["classname"]. ToString () + "',";
Strjson + = "'value': '" + dt. Rows [0] ["classid"]. ToString () + "',";
Strjson + = "'showcheck': true ,";
Strjson + = "'complete': true ,";
Strjson + = "'checktate': 0 ,";
Strjson + = "'haschildren ':" + haschild. ToString (). ToLower () + ",";
Strjson + = "'childnodes ':";
If (! IsHasChild (pid ))
{
Strjson + = "null }";
}
Else
{
Strjson + = "[";
DataTable mydt = DBUtility. db. ExecuteTable ("select * from class where parientid =" + pid );
For (int I = 0; I <= mydt. Rows. Count-1; I ++)
{
Strjson + = GetOtherJson (Convert. ToInt32 (mydt. Rows [I] ["classid"]. ToString () + ",";
}
Strjson = strjson. Substring (0, strjson. Length-1 );
Strjson + = "]}";
}
Return strjson;
}
Private bool IsHasChild (int pid)
{
DataTable dt = DBUtility. db. ExecuteTable ("select * from class where parientid =" + pid );
If (dt. Rows. Count = 0)
{
Return false;
}
Else
{
Return true;
}
}
Finally, you can just look at the database and build it. Thanks again, not serious.