/****************************** Tree Organization Framework List v1.0 2011 1 Month 6 Author: flycrosscloud *************************************/ //Initialization framework var allImages = { HasNodeClose: "", //Contains child nodes, closed state (not the last one) HasNodeOpen: "", //Contains child nodes, open status (not the last one) LastHasNodeClose: "", //Contains child nodes, closed state (the last one) LastHasNodeOpen: "", //Contains child nodes, open Status (last one) CommonNode: "", //Does not contain child nodes, ordinary node (not the last one) LastCommonNode: "< img src='image/ftv2lastnode.gif'/>", //Does not contain child nodes, ordinary node (last one) NodeLine: "" , //Connection between nodes NodeClose: "", //Node closed status NodeOpen: "", //Node open status NodeBlank: ""//Blank connection }; $( function () { $.post("http://localhost/system/asmx/wsTree.asmx/HelloWorld", function (data) { InitTree(data); }); }) ; function InitTree(org_data) { var org = eval("(" org_data ")"); drawtree(org, 1, "", "#nodeTree"); $("#nodeTree img").bind("click", function (event) { $(this).parent().find("ul").toggle();
}); } function drawtree(org, s, pPreLine, ulname) { var orgLength = org.length; var PreLine; var count = s;
for (var i = 0; i < orgLength; i ) { var NodeImg = allImages.NodeClose; //Pre-project icon var PreNodeLine; //Project Connection before icon //Determine the icon before the project if (org[i].ChildUnits != null)//If it contains child nodes { NodeImg = allImages.NodeOpen; } //Determine the connection line before the graph if ((org[i].ChildUnits != null) && (i == orgLength - 1)) { //Contains child nodes and Is the last node of this layer PreNodeLine = allImages.LastHasNodeOpen; } if ((org[i].ChildUnits == null) && (i == orgLength - 1)) { //Does not contain child nodes and is the last node of this layer PreNodeLine = allImages.LastCommonNode; } if ((org[i].ChildUnits != null) && (i != orgLength - 1)) { //Contains child nodes and is not the last node of this layer PreNodeLine = allImages.HasNodeOpen; } if ((org[i].ChildUnits == null) && (i != orgLength - 1)) { //Does not contain child nodes and is not the last node of this layer PreNodeLine = allImages.CommonNode; } if ( i == orgLength - 1) { PreLine = pPreLine allImages.NodeBlank; } else { PreLine = pPreLine allImages.NodeLine; } var temp = $("
My level is limited, so I thought about this stuff for several days before I came up with a semi-finished product. There are still some unresolved issues, so I’ll put them here for memo, and I hope experts can give me some advice. Idea: Use nested
tags to implement, use one
at each level, use
nested
for lower-level nodes, and implement it recursively. At the beginning, everything was done using
, but I found that it was too troublesome to achieve hidden appearance. Questions: 1. The connection under IE is intermittent. I’m not familiar with CSS and haven’t figured it out yet. I feel it’s just fine, so I’m too lazy to do it anymore, haha. 2. The front image needs to be changed when hidden and visible. This has not been implemented yet, but I feel that it is not a big problem. I won’t post the background code. Please leave a message if you need it. It’s actually very simple, but the recursive sorting of nodes is the troublesome part. Display effect:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn