Javascript tree menu Method

Source: Internet
Author: User

Javascript tree menu Method

Seeing that yuanyou published an article about the JS tree, after reading it, I thought it was possible to streamline a lot of code,

I thought that a JS tree was used in the previous project, so I tried to modify it. Now I have posted the code to share it with you. I also ask you to throw more bricks!

<! DOCTYPE html PUBLIC "-// W 3C // Dtd xhtml 1.0 Transitional // EN "" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<Html xmlns = "http://www.w3.org/1999/xhtml">

<Head runat = "server">

<Title> </title>

<Script src = "JS/Tree. js" type = "text/javascript"> </script>

</Head>

<Body>

<Form id = "form1" runat = "server">

<Div>

<% -- <Asp: TreeView ID = "TreeView1" runat = "server" ShowLines = "True">

</Asp: TreeView> -- %>

<Div id = "treeOrgan"> </div>

</Div>

</Form>

<Script type = "text/javascript" language = "javascript">

Var tree;

Window. onload = function ()

{

If (tree! = ""){

Tree = new treeview ("treeview", "../images/Tree", false, false );

Var parNode = new node ("personnel list", "personnel list", "", "0", "F", false ,"");

// Caption, title, url, target, tag, check, callback

Tree. add (parNode );

Tree. create (document. getElementById ("treeOrgan "));

InitNode (0, parNode );

ParNode. expand ();

}

}

Function InitNode (id, parNode ){

If (parNode. nodes. length> 0 ){

ParNode. toggle ();

}

Else {

// ParNode. DeleteChildren ();

Var result = WebApplicationJsTree. _ Default. GetJson (id). value;

If (result! = Null & result! = ""){

Var data = eval ('+ result + ')');

For (var I = 0; I <data. length; I ++ ){

Var pn = new node (data [I]. NAME, data [I]. NAME, "", "P", data [I]. id, true ,"");

ParNode. add (pn );

}

}

}

}

Treeview. prototype. onnodeclick = function (sender ){

InitNode (sender. tag, sender );

Sender. select ();

Sender. expand ();

Return false;

}

</Script>

</Body>

</Html>

In fact, I personally think that using TreeView + linq to list will connect to the server once, and the performance of small data volumes should be quite high. The Code is also in the source package.

In the interaction with the client, you can add

Tn. Text = "<span onclick = \" treeNodeClick ("+ tn. ID +") \ ">" + tn. Name;

Database Structure:

FF:

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.