<% -- Tree. jsp -- %>
<% @ Page pageencoding = "GBK" contenttype = "text/html; charset = GBK" Import = "Java. util. arraylist" %>
<% @ Taglib uri = "/Struts-tags" prefix = "S" %>
<LINK rel = "stylesheet" href = "$ {myroot}/jquery/jquery.treeview.css"/>
<LINK rel = "stylesheet" href = "$ {myroot}/jquery/screen.css"/>
<SCRIPT src = "$ {myroot}/jquery. js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "$ {myroot}/jquery. Treeview. js" type = "text/JavaScript"> </SCRIPT>
<%
// Need: struts2, jquery tree plug-in, which is: http://jquery.bassistance.de/treeview/jquery.treeview.zip
// An infinite hierarchy of trees -- Ren Wenmin, author of Chenzhou Tuo vocational software College
// Simulate database data: each row of data includes the self ID, self content, and parent ID.
Arraylist ary = new arraylist (); // all data
String [] ary1 = new string [] {"1", "Item1", "0"}; // data in each row
Ary. Add (ary1 );
Ary1 = new string [] {"2", "item2", "0 "};
Ary. Add (ary1 );
Ary1 = new string [] {"3", "item3", "0 "};
Ary. Add (ary1 );
Ary1 = new string [] {"4", "item1_1", "1 "};
Ary. Add (ary1 );
Ary1 = new string [] {"5", "item1_2", "1 "};
Ary. Add (ary1 );
Ary1 = new string [] {"6", "item1_2_1", "5 "};
Ary. Add (ary1 );
Ary1 = new string [] {"7", "item1_2_2", "5 "};
Ary. Add (ary1 );
Ary1 = new string [] {"8", "item2_1", "2 "};
Ary. Add (ary1 );
Ary1 = new string [] {"9", "item2_1_1", "8 "};
Ary. Add (ary1 );
Ary1 = new string [] {"10", "item2_2", "2 "};
Ary. Add (ary1 );
Ary1 = new string [] {"11", "item3_1", "3 "};
Ary. Add (ary1 );
Ary1 = new string [] {"12", "item3_2", "3 "};
Ary. Add (ary1 );
Request. setattribute ("datas", Ary );
%>
<SCRIPT type = "text/JavaScript">
$ (Document). Ready (function (){
VaR oappend;
<S: iterator value = "# request. datas" id = "T">
If ($ ("# ul $ {T [2]}"). size () = 0) {// if the parent ul cannot be found, create the parent UL and attach it to the parent Li
Oappend = $ ("<ul id = 'ul $ {T [2]} '> <li id = 'Li $ {T [0]}'> <input type =' checkbox 'value = 'ck $ {T [0]} '/>$ {T [1]} </LI> </ul> "). appendto ($ ("# li $ {T [2]}");
}
Else {// if the father ul finds it, it is directly attached to the father ul
Oappend = $ ("<li id = 'Li $ {T [0]} '> <input type = 'checkbox' value = 'ck $ {T [0]}'/ >$ {T [1]} </LI> "). appendto ("# ul $ {T [2]}");
}
</S: iterator>
$ ("# Ul0"). Treeview ({// display the entire tree through the root node container
});
});
</SCRIPT>
<! -- Hold the UL of the root node. Here 0 is the Father's Day of the root node -->
<Ul id = "ul0"> </ul>