<% -- 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://xiazai.jb51.net/200910/other/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>
Jquery tree plugin, which is: http://xiazai.jb51.net/200910/other/jquery.treeview.zip