Struts2 + jquery creates an infinite hierarchy of trees

Source: Internet
Author: User

<% -- 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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.