今天下午刚写的树形控件

[code]
var HK_TreeNode = function(pNode){
var me = this;
var nodeValue = "";
var nodeImage = document.createElement("img");
var nodeElement = document.createElement("div");
var nodeText = document.createElement("div");
var childLayout = document.createElement("div");
nodeElement.appendChild(nodeImage);
nodeElement.appendChild(nodeText);
nodeElement.appendChild(childLayout);
nodeImage.src="images/plus.png";
nodeImage.className = "tree_nodeimage";
nodeText.className = "tree_nodetext";
childLayout.className = "tree_nodelayout";
childLayout.style.display = "none";
var nodeIndex = -1;
var parentNode = null;
var level = 0;
var items = new Array();
if(parentNode!=null){
level = pNode.level + 1;
parentNode = pNode;
}
this.tree = null;
this.data = null;
this.setActive = function(){
var activeNode = this.tree.activeNode;
if(activeNode!=null){
activeNode.deActive();
}
nodeText.className = "tree_nodetextActive";
this.tree.activeNode = this;
}
this.deActive = function(){
this.tree.activeNode = null;
nodeText.className = "tree_nodetext";
}
this.appendChild = function(node){
nodeIndex = items.push(node);
childLayout.appendChild(node.getElement());
nodeImage.src="images/plus.gif";
}
this.expand = function(){
if(childLayout.style.display != "none"){
nodeImage.src="images/plus.gif";
childLayout.style.display = "none";
}else{
if(items.length>0){
nodeImage.src="images/plusExpand.gif";
childLayout.style.display = "";
}
}
}
this.getCount = function(){
return items.length;
}
this.getLevel = function(){
return level;
}
this.setParentNode = function(node){
parentNode = node;
node.appendChild(nodeElement);
}
this.getParentNode = function(){
return node;
}
this.getElement = function(){
return nodeElement;
}
this.getImageElement = function(){
return nodeImage;
}
this.getTextElement = function(){
return nodeText;
}
this.setText = function(value){
nodeText.innerText = value;
}
this.getText = function(){
return nodeText.innerText;
}
this.setValue = function(value){
nodeValue = value;
this.setText(value);
}
this.getValue = function(){
return value;
}
function onnodeclick(){
me.expand();
}
function onnodetextclick(){
me.setActive();
}
function ontextdblclick(){
me.expand();
}
function onselect(){
return false;
}
nodeElement.attachEvent("onselectstart",onselect);
nodeText.attachEvent("onclick",onnodetextclick);
nodeText.attachEvent("ondblclick",ontextdblclick);
nodeImage.attachEvent("onclick",onnodeclick);
}

var HK_Tree = function(){
var me = this;
var layout = document.createElement("div");
var items = new Array();
var map = new Object();
var root = new Array();
var activeNode = null;
this.xml = null;
this.parent = null;
this.primaryField = "";
this.parentField = "";
this.valueField = "";
this.textField = "";
this.activeNode = null;
this.appendNode = function(parentNode){
var node = new HK_TreeNode(parentNode);
if(parentNode!=null){
parentNode.appendChild(node);
}else{
layout.appendChild(node.getElement());
root.push(node);
}
node.tree = this;
items.push(node);
return node;
}
this.getNodeByIndex = function(index){
if(items[i]!=undefined){
return items[i];
}
return null;
}
this.getNodeByName = function(name){
if(map[name]!=undefined){
return map[name];
}
return null;
}
this.getCount = function(){
return items.length;
}
this.laodxml = function(){

}
this.databand = function(){
var oRows = this.xml.getElementsByTagName("Row");
var oCol,oCells,oRow;
for(var i=0;i<oRows.length;i++){
var parentId = oRows[i].selectSingleNode("./field[@name='"+this.parentField+"']");
var nodeId = oRows[i].selectSingleNode("./field[@name='"+this.primaryField+"']");
var nodeValue = oRows[i].selectSingleNode("./field[@name='"+this.valueField+"']");
var nodeText = oRows[i].selectSingleNode("./field[@name='"+this.textField+"']");
if(parentId!=null&&nodeId!=null){
var node = this.appendNode(this.getNodeByName(parentId.text));
node.data = oRows[i].xml;
if(nodeValue!=null){
node.setValue(nodeValue.text);
}
if(nodeText!=null){
node.setText(nodeText.text);
}
map[nodeId.text] = node;
}

}
this.ondataband();
}
this.init = function(){
this.parent.appendChild(layout);
}
this.ondataband = function(){};
}

var tree = new HK_Tree();
tree.parent = document.getElementById("treepanel");
tree.primaryField = "unitId";
tree.parentField = "parentUnitId";
tree.valueField = "name";
tree.textField = "name";
tree.init();
[/code]
今天下午完成的,发上来给大家看看
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值