完成dhtmlxtree控件替换treelist.htc

     今天主要是完成dhtmlxtree控件代替原来的treelist。因为dxtree更漂亮,与其他dhtmlx控件一起使用,整体风格一致。

     但是dhtmlxtree有几个缺陷:首先是导入的xml文件的格式有要求,需要<tree>表示树,<item>表示节点,其他标签一律不认。其次是他只能获取id,text的属性。

     目前采取的解决办法是:将不符合dhtmlx的xml格式的文件,进行字符串替换,换成符合要求的格式。另外对于更大属性的获取,则需要修改下dhtmlxtree.js文件。

开头部分添加

function dhtmlXTreeObject(htmlObject, width, height, rootId){ if (_isIE) try { document.execCommand("BackgroundImageCache", false, true); } catch (e){} if (typeof(htmlObject)!="object") this.parentObject=document.getElementById(htmlObject); else this.parentObject=htmlObject; this.parentObject.style.overflow="hidden"; this._itim_dg=true; this.dlmtr=","; this.dropLower=false; this.enableIEImageFix(); this.xmlstate=0; this.mytype="tree"; this.smcheck=true; //smart checkboxes this.nodeClick=[];//add by DongL 20101108 this.attribute=[];//add by xcl 2010-11-11 属性字段 this.attributeValue=[];//属性字段对应的值 this.width=width; this.height=height; 

后面部分添加

//add by xcl 2010-11-11 获取被选中item对应属性的值 dhtmlXTreeObject.prototype.getAttributeValue=function(id){ if(this.attributeValue){ var attid = this.getSelectedItemId()+id; return this.attributeValue[attid]; } } //add by xcl 2010-11-11 设置需要记录的属性字段 dhtmlXTreeObject.prototype.setAttribute=function(id){ this.attribute.push(id); } dhtmlXTreeObject.prototype._parseItem=function(c,temp,preNode,befNode){ var id; if (this._srnd && (!this._idpull[id=c.get("id")] || !this._idpull[id].span)) { this._addItemSRND(temp.id,id,c); return; } //add by DongL 20101108 dhtmlXTreeObject.prototype.getNodeClickEvent=function(id){ if(this.nodeClick){ return this.nodeClick[id]; } } var a=c.get_all(); if ((typeof(this.waitUpdateXML)=="object")&&(!this.waitUpdateXML[a.id])){ this._parse(c,a.id,1); return; } // add by DongL 20101108 if(c.get('clickEvent')){ this.nodeClick[c.get('id')]=c.get('clickEvent'); } for(var n=0;n<this.attribute.length;n++){ var att = this.attribute[n]; var attid = c.get('id')+att; if(c.get(att)){ this.attributeValue[attid] = c.get(att); } } //#__pro_feature:01112006{ if ((a.text===null)||(typeof(a.text)=="undefined")){ a.text=c.sub("itemtext"); if (a.text) a.text=a.text.content(); } //#} var zST=[]; if (a.select) zST.push("SELECT"); if (a.top) zST.push("TOP"); if (a.call) this.nodeAskingCall=a.id; if (a.checked==-1) zST.push("HCHECKED"); else if (a.checked) zST.push("CHECKED"); if (a.open) zST.push("OPEN"); if (this.waitUpdateXML){ if (this._globalIdStorageFind(a.id)) var newNode=this.updateItem(a.id,a.text,a.im0,a.im1,a.im2,a.checked); else{ if (this.npl==0) zST.push("TOP"); else preNode=temp.childNodes[this.npl]; var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,0,preNode); preNode=null; } } else var newNode=this._attachChildNode(temp,a.id,a.text,0,a.im0,a.im1,a.im2,zST.join(","),a.child,(befNode||0),preNode); if (a.tooltip) newNode.span.parentNode.parentNode.title=a.tooltip; if (a.style) if (newNode.span.style.cssText) newNode.span.style.cssText+=(";"+a.style); else newNode.span.setAttribute("style",newNode.span.getAttribute("style")+"; "+a.style); if (a.radio) newNode._r_logic=true; if (a.nocheckbox){ var check_node=newNode.span.parentNode.previousSibling.previousSibling; check_node.childNodes[0].style.display='none'; if (window._KHTMLrv) check_node.style.display="none"; newNode.nocheckbox=true; } if (a.disabled){ if (a.checked!=null) this._setCheck(newNode,a.checked); this.disableCheckbox(newNode,1); } newNode._acc=a.child||0; if (this.parserExtension) this.parserExtension._parseExtension.call(this,c,a,(temp?temp.id:0)); this.setItemColor(newNode,a.aCol,a.sCol); if (a.locked=="1") this.lockItem(newNode.id,true,true); if ((a.imwidth)||(a.imheight)) this.setIconSize(a.imwidth,a.imheight,newNode); if ((a.closeable=="0")||(a.closeable=="1")) this.setItemCloseable(newNode,a.closeable); var zcall=""; if (a.topoffset) this.setItemTopOffset(newNode,a.topoffset); if ((!this.slowParse)||(typeof(this.waitUpdateXML)=="object")){ if (c.sub_exists("item")) zcall=this._parse(c,a.id,1); } //#__pro_feature:01112006{ //#smart_parsing:01112006{ else { if ((!newNode.childsCount) && c.sub_exists("item")) newNode.unParsed=c.clone(); c.each("userdata",function(u){ this.setUserData(a.id,u.get("name"),u.content()); },this); } //#} //#} if (zcall!="") this.nodeAskingCall=zcall; c.each("userdata",function(u){ this.setUserData(c.get("id"),u.get("name"),u.content()); },this) } 

 

  明天的工作:tree控件的收尾工作,下一步研究下地图显示慢的原因。老是卡在那也不行啊。

你可能感兴趣的:(object,function,tree,null,2010,Parsing)