JS tree sorted by ID, parent ID

Source: Internet
Author: User
JS tree sorted by ID, parent ID

Get Contact
var datas = sfilename.selectnodes ("Datas/data");
var list = new Array ();
var data = new Array ();
for (var i = 0; i < datas.length; i++) {
if (Datas[i].getattribute ("type") = = "folder") {
List.push (Datas[i]);
} else {
Data.push (Datas[i]);
}
}
Set the initial parent number
var fatherno =-1;
Show Table of Contents
Showtreelist (tree, Fatherno, datas, list, data, NULL, "");

Change the picture and hide the display div
function expand (Div, img) {
if (Div.style.display = = "Block") {
Div.style.display = "None";
IMG.SRC = "Images/pic/skin_nline/closed.gif";
} else {
Div.style.display = "block";
IMG.SRC = "Images/pic/skin_nline/opened.gif";
}

}

Recursive display tree
function showtreelist (tree, Fatherno, datas, list, data, CurrentNode, LISTSTRBLANK2) {
Create a Div
var treediv = document.createelement ("div");
var isdisplay = "1"//node state defaults to display state
Treediv.id = "Treediv" + Isdisplay + Fatherno;
if (CurrentNode) {
tree.innerhtml + = ListStrblank2 + " ' + currentnode.getattribute ("group name") + "<br>";
}
Treediv.style.display = "block";
document.getElementById ("Monitorobject"). AppendChild (Treediv);

Displays the group name if CurrentNode exists

var L = ischildlist (Fatherno, list);
If there is a subdirectory, then in the secondary loop. No, no, no, no information.
if (l.length!= 0) {
LISTSTRBLANK2 = "&nbsp;&nbsp;";
for (var j = 0; J < L.length; J + +) {
Showtreelist (Treediv, L[j].getattribute ("id"), datas, list, data, L[j], LISTSTRBLANK2);
}
}

var d = ischilddata (Fatherno, data);
If there are child information, then the secondary loop. No, no, no, no, no information.
if (d.length!= 0) {
for (var j = 0; J < D.length; J + +) {
treediv.innerhtml + = ListStrblank2 + "<input type= ' checkbox ' name= ' pname ' Value= ' "+ d[j].getattribute (" Object attribute ") +" ' > "+" Beauty "+" <br> ";
}
}
Tree.appendchild (TREEDIV);
}

Determine if there are subfolders
function Ischildlist (Fatherno, lists) {
Define an object that holds subdirectories
var L = new Array ();
Loop to find subdirectories
for (var i = 0; i < lists.length; i++) {
If the parent number is the same as the parent number, save the
if (Lists[i].getattribute ("parent number") = = Fatherno) {
L.push (Lists[i]);
}
}
return l;
}

Determine if there are any child information
function Ischilddata (Fatherno, datas) {
var d = new Array ();
for (var i = 0; i < datas.length; i++) {
if (Datas[i].getattribute ("parent number") = = Fatherno) {
D.push (Datas[i]);
Alert (Datas[i].getattribute ("object property"));
}
}
return D;
}

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.