项目中用到了dtree,别问我为什么用这么古老的插件,因为简单啊orz,文件树的条目不多,detree加载卡顿的问题也不用解决,开森。
在使用过程中在选择节点后需要自定义一些onclick的动作,本来是打算在html中加script就完了,但是死活实现不了,就只能在原代码上动手了。
我要实现的是点击一个节点,自动进行搜索和呈现出一个datatable:
dTree.prototype.s = function(id) { if (!this.config.useSelection) return; var cn = this.aNodes[id]; if (cn._hc && !this.config.folderLinks) return; if (this.selectedNode != id) { if (this.selectedNode || this.selectedNode==0) { var eOld = document.getElementById("s" + this.obj + this.selectedNode); eOld.className = "node"; } eNew = document.getElementById("s" + this.obj + id); eNew.className = "nodeSel"; this.selectedNode = id; if (this.config.useCookies) this.setCookie('cs' + this.obj, cn.id); var father_tag = eNew.innerText.search(/^\s/) + 1; if(father_tag){ var selected_cancer_name = eNew.innerText.replace(/^\s/,""); if(selected_cancer_name != "ALL types"){ var result_arr = browse_search(selected_cancer_name,"main_cancer"); show_result(result_arr); } else { var result_arr = browse_search(".*","main_cancer"); show_result(result_arr); } } else { var result_arr = browse_search(eNew.innerText, "subtype"); show_result(result_arr); } } };
其中father_tag是我用来区分是不是父节点的,因为搜索的条目不同,我用的方法是在父节点前加一个空格和子节点加以区分。
如对本文有疑问, 点击进行留言回复!!
同事牛逼啊,写了个隐藏 bug,我排查了 3 天才解决问题!
【JavaScript笔记(一)】万丈高楼平地起 - 基本概念篇
轻松解决 org.apache.taglibs.standard.tlv.JstlCoreTLV 困惑
网友评论