Mztreeview 1.0__tree

Source: Internet
Author: User

Mztreeview 1.0 is a Web script tree that data is loaded at once and the client nodes are displayed asynchronously. The theoretical node number of Mztreeview 1.0 has a maximum design limit of 100,000 nodes, and the page opening time is less than 3 seconds in the case of 30,000 nodes. The hierarchical composition of the number of infinite-level infinite nodes: ID parentid. That is, each node in addition to its own node ID and its parent layer node ID, in this way can be combined into an infinite level of the tree.

In Mztreeview, there is a virtual root node with an ID of 0, and the user-visible root node has a parent node ID of 0

Property

Some properties of the Mztreeview class:
Property name
Type
Specific description of the attribute

Mztreeview.nodes
Collection
Server-side to the tree to specify the data source of data storage objects, specific storage format such as:
mztreeviewhandle.nodes["Parentid_nodeid"] = "text:nodetext; Icon:nodeicon; Url:nodeurl; ...";

Mztreeview.url
Address string
Read-write, tree default URL, default value is #

Mztreeview.target
Target Frame Name
Read-write, tree default link target, default value is _self

Mztreeview.name
Character
Read-only, instance name of the tree, passed as a parameter when the tree was instantiated (case sensitive):
var tree = new Mztreeview ("Tree");

Mztreeview.currentnode
Tree node
Read-only, node object in which the tree currently has focus

Mztreeview.icons
Collection
All icons used by the tree are stored

Mztreeview.iconsexpand
Collection
The icon of the expanded state in the tree is stored

Mztreeview.colors
Collection
Several colors used in the tree to store

Mztreeview properties that are owned by the client node:

Property name
Specific description of the attribute

Node.id
Numeric text, ID of the node

Node.parentid
numeric text, the parent node ID of the node

Node.text
Text, display text for a node

Node.hint
Text, comment Description of the node

Node.icon
text, corresponding icon of the node

Node.path
text, the absolute path of the node in the tree: 0_1_10_34

Node.url
Text, the URL of the node

Node.target
Text, the target frame name of the node link

Node.data
Text, the data on which the node is mounted

Node.method
Text, the click of the node corresponds to the processing statement

Node.parentnode
object, the parent node object of the node

Node.childnodes
An array that contains all the child nodes under the node

Node.sourceindex
Text, server-given data in the Parentid_nodeid of the object's combination string

Node.haschild
Boolean value that indicates whether the node has child nodes

Node.isload
Boolean value, whether the child node data for this node is already initialized on the client

Node.isexpand
Boolean value, the expanded state of the node


Method

Some methods of the Mztreeview class:

Method name
Specific description of the method

Mztreeview.tostring ()
Default initial run of class

Mztreeview.buildnode (ID)
Converts all subordinate child nodes of the node to HTML and manifests on the Web page

mztreeview.nodetohtml (node, AtEnd)
Convert node to HTML

Mztreeview.load (ID)
To load all child nodes under the current node from the data source

Mztreeview.nodeinit (Sourceindex, ParentID)
The initial information of node, from data source to client complete node transformation

Mztreeview.focus (ID)
Clustered to a node

Mztreeview.expand (id[, Sureexpand])
Expand node (load initialization with subordinate child node data)

Mztreeview.seticonpath (PATH)
Set the correct path to the node picture

Mztreeview.nodeclick (ID)
Click event to be triggered when the node link is clicked

Mztreeview.uppernode ()
Jumps to the parent node of the current clustered node

Mztreeview.lowernode ()
Jumps to a child node of the current clustered node

Mztreeview.pervnode ()
Jumps to the previous node of the current clustered node

Mztreeview.nextnode ()
Jumps to the next node of the current clustered node

Mztreeview.expandall ()
Expand all the tree points, this step will be time-consuming when the total node is greater than 500

The following is a simple example:

To import a 1.0 jar package

JSP page code:

<%@ page language= "java" import= "java.util.*" pageencoding= "UTF-8"%>
<%
String path = Request.getcontextpath ();
String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";
%>

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
<script language= "JavaScript" src= "Tree/mztreeview1.0/mztreeview10.js" ></script>
<body>
<input type= "button" value= "Expand All Nodes" onclick= "Testtree.expandall ()"/>

<style>
A.mztreeview {
font-size:9pt;
padding-left:3px;
}
</style>
<div id= "Treeviewarea" >
<script language= "JavaScript" >
var testtree = new Mztreeview ("Testtree");
Testtree.icons["Property"] = "tree/mztreeview1.0/property.gif";
testtree.icons["css" = "tree/mztreeview1.0/collection.gif";
testtree.icons["book"] = "tree/mztreeview1.0/book.gif";
testtree.iconsexpand["book"] = "tree/mztreeview1.0/bookopen.gif"; Picture to expand
Testtree.seticonpath ("tree/mztreeview1.0/"); Available relative paths
<%
String treedata = (string) request.getattribute ("Treedata");
Out.print (Treedata);
%>
tree.nodes[' 0_1 '] = "Text: Inspection information management;";
tree.nodes[' 1_2 '] = "text: Purchased product inspection Group;";
tree.nodes[' 1_3 '] = "Text: final product inspection;";
tree.nodes[' 1_4 '] = "text: retest condition;";
tree.nodes[' 1_5 '] = "text: Office Assistant;";
tree.nodes[' 1_6 ' = "Text: basic information management;";
tree.nodes[' 1_7 '] = "Text: departmental observations and recommendations;";
tree.nodes[' 1_8 '] = "Text: systematic comments and suggestions;";


Tree.seturl ("catalog.asp");
Tree.settarget ("Mzmain");


document.write (Testtree.tostring ());
document.getElementById (' Treeviewarea '). InnerHTML = Testtree.tostring ();

</script>
</div>
</body>

Background code: Using JDBC to search data from the database

Package tree;

Import java.io.IOException;
Import Java.io.PrintWriter;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.ArrayList;
Import java.util.List;

Import javax.servlet.ServletException;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;

@SuppressWarnings ("Serial")
public class MzTreeView10 extends HttpServlet {

Public MzTreeView10 () {
Super ();
}

public void Destroy () {
Super.destroy ();
}

public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {

This.dopost (request, response);

}

public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {

Response.setcontenttype ("text/html");
List<tree> trees = This.getresultset ();
String treename = "testtree";//This is the name of the tree to be the same as the name of the page

StringBuffer TREEBF = new StringBuffer ("");

Treebf.append (Treename). Append (". nodes[/" 0_1/"]=/" Text: root node/";");
System.out.println (Trees.size ());
for (tree tree:trees) {
if (tree.getpid () = = 0) {
Treebf.append ("n"). Append (Treename);
Treebf.append (". nodes[/"). Append (Tree.getpid () + 1);
Treebf.append ("_"). Append (Tree.getid () + 1). Append ("/"]=/");
String text = Tree.getdesc ();
if (text!= null && text.trim ()!= "") {
Treebf.append ("text:"). Append (Text). Append (";");
Treebf.append ("Method:alert" + tree.getpid () + "_"
+ Tree.getid () + "JS method");
}
Treebf.append ("/"; ");
} else {
Treebf.append ("n"). Append (Treename);
Treebf.append (". nodes[/"). Append (Tree.getpid () + 1);
Treebf.append ("_"). Append (Tree.getid () + 1). Append ("/"]=/");
String text = Tree.getdesc ();
if (text!= null && text.trim ()!= "") {
Treebf.append ("text:"). Append (Text). Append (";");
Treebf.append ("Method:alert" + tree.getpid () + "_"
+ Tree.getid () + "JS method");
}
Treebf.append ("/"; ");
}

}
System.out.println (Treebf.tostring ());
Request.setattribute ("Treedata", treebf.tostring ());
Request.getrequestdispatcher ("/tree10.jsp"). Forward (request, response);

}

public void Init () throws Servletexception {
}

Public list<tree> Getresultset () {
Connection conn = null;
PreparedStatement PSM = null;
ResultSet rs = null;
String sql = "SELECT * from tree";
list<tree> trees = new arraylist<tree> ();
try {
Class.forName ("Org.gjt.mm.mysql.Driver");
conn = Drivermanager.getconnection (
"Jdbc:mysql://localhost:3306/dwr", "Root", "" ");
PSM = conn.preparestatement (sql);
rs = Psm.executequery ();
Tree tree = null;
while (Rs.next ()) {
Tree = new Tree ();
Tree.setid (Rs.getint ("id"));
Tree.setdesc (rs.getstring ("desc"));
Tree.setpid (Rs.getint ("pid"));
Trees.add (tree);
}
catch (Exception e) {
E.printstacktrace ();
finally {
try {
if (Rs!= null) {
Rs.close ();
}
catch (SQLException e) {
}
try {
if (PSM!= null) {
Psm.close ();
}
catch (SQLException e) {
}
try {
IF (conn!= null) {
Conn.close ();
}
catch (SQLException e) {
}
}
return trees;
}

}

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.