Home > Article > Web Front-end > JXTree object, read external xml file data, function to generate tree_javascript skills
/******************************************
*JXTree object, read external xml file data, spanning tree
*@author brull
*@email brull@163.com
*@date 2007-03-27
********** *****************************/
/*
*@param xmlURL XML文件的地址
*/
var JXTree = function(xmlURL)
{
var result = new Array();
/*****************************
*First define the TreeNode abstract object
*TreeNode object attributes:
*id unique Number, must be defined in the xml file as a node attribute
*level node level, starting from -1 (i.e. root node)
*_click node click, defined in the xml file as a node attribute [optional]
*isLast Whether it is the last node in the level where this node is located
*parent_isLast Whether the parent node is the last node in the level where the parent node is located
*toHTML How to convert this node into HTML code
****** *************************/
var TreeNode = function (node,level)
{
var parent_elements = node.parentNode ? (node.parentNode.parentNode ? node.parentNode.parentNode.childNodes : null) : null;
var elements = node.parentNode ? node.parentNode.childNodes : null;
this.id = XMLDom.getAttribute(node,"id") ? XMLDom.getAttribute(node,"id") : "";
this.level = level;//节点的层次
this.isLast = elements ? ((elements.item(elements.length-2) === node) ? true : false) : false;
this._click = XMLDom.getAttribute(node,'click') ? XMLDom.getAttribute(node,'click') : "";
this.toHTML = null;//function
}
/*****************************
*ElementNode object, inherited from abstract object TreeNode
*New attributes:
*_nodeName Node name
*****************************/
var ElementNode = function(node,level)
{
TreeNode.apply(this,arguments);
this._nodeName = XMLDom.getAttribute(node,"name") ? XMLDom.getAttribute(node,"name") : "";
this.toHTML = function(){
var result = "";
if(this.isLast) result = "