- 浏览: 382048 次
- 性别:
- 来自: 北京
-
文章分类
- 全部博客 (116)
- 生活 (1)
- 工作 (56)
- 健康 (0)
- 感情 (0)
- IT (45)
- 数据库 (11)
- Spring处理lob数据 (0)
- org.springframework.dao.InvalidDataAccessApiUsageException: OracleLobCreator needs to work on [oracle.jdbc.OracleConnection] (1)
- not on [com.mysql.jdbc.Connection]: specify a corresponding NativeJdbcExtractor; nested exception is java.lang.ClassCastException: com.mysql.jdbc.Connection (1)
- org.hibernate.DuplicateMappingException (1)
- js (3)
- Spring (2)
- PropertyPlaceholderConfigurer (1)
- Spring事务 (2)
- PROPAGATION_REQUIRED (1)
- PROPAGATION_SUPPORTS (1)
- PROPAGATION_MANDATORY (1)
- PROPAGATION_REQUIRES_NEW (1)
- setTimeout() (0)
- fn函数 (1)
- jstl标签 (1)
- 锚点 (1)
- 工作 urlrewrite 静态化 (1)
- 分享到微博 (1)
- hibernate (1)
- id to load is required for loading (1)
最新评论
-
wangyudong:
用Holer,只需要配置一个Access Key就搞定了htt ...
webservice发布以后在本地能够访问,但是在远程访问不了 -
梦幻无极:
[flash=200,200][url][img][list] ...
mysql Error Code : 1060 Duplicate column name 'ID' -
wqxdoc_pxiang9:
工程用什么软件
plc学习笔记 -
jiangxiankun:
请问一下这个需要什么jar包吗
用JAVA代码访问一段URL地址是否可用怎么写? -
361010911:
好乱!- -
java轮询程序的实现
最近在做设备管理系统的需求规约文档,今天弄好了,想想以后会用到dtree。所以我就看了看dtree。
下面是dtree.js中的内容。这个dtree中节点带有复选框。
function StringBuilder() {//add a function to increase speed
this.__strings__ = new Array;
}
StringBuilder.prototype.append = function (str) {
this.__strings__.push(str);
};
StringBuilder.prototype.toString = function () {
return this.__strings__.join("");
};
var hashmap=new Hash();
function Node(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen,isError) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title;
this.target = target;
this.icon = icon;
this.iconOpen = iconOpen;
this.isError = isError;
this._io = open || false;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
this._ic = check || false;
this._ro= readOnly || false;
this.hasCheckbox = hasCheckbox;
};
// Tree object
function dTree(objName,imageUrl) {
if (imageUrl==null) imageUrl = '/skins/default/images/treeimages/';
if (objName==null) objName = 'Tree';
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : false,
useStatusText : false,
closeSameLevel : false,
inOrder : false,
useCheckbox4c :true,
useCheckbox4p :true,
preOpenChecked:true
,
relationCheck:true //是否加载父子的check关系,比如check父的时候所有子节点被check
}
this.icon = {
root : imageUrl+'base.gif',
folder : imageUrl+'folder.gif',
folderOpen : imageUrl+'folderopen.gif',
node : imageUrl+'page.gif',
empty : imageUrl+'empty.gif',
line : imageUrl+'line.gif',
join : imageUrl+'join.gif',
joinBottom : imageUrl+'joinbottom.gif',
plus : imageUrl+'plus.gif',
plusBottom : imageUrl+'plusbottom.gif',
minus : imageUrl+'minus.gif',
minusBottom : imageUrl+'minusbottom.gif',
nlPlus : imageUrl+'nolines_plus.gif',
nlMinus : imageUrl+'nolines_minus.gif'
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
// Adds a new node to the nodes array
dTree.prototype.add = function(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen, isError) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen, isError);
if(hashmap.containsKey(pid)){//key:parent id value :array which record childs' id
var arrayValue=hashmap.getItem(pid).value;
arrayValue.push(this.aNodes.length-1);
}else{
var tempArray=new Array();
tempArray.push(this.aNodes.length-1);
hashmap.add(pid,tempArray);
}
};
// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies)this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var addNodesb=new StringBuilder();
var n=0;
if (this.config.inOrder) n = pNode._ai;
var childArray=hashmap.getItem(pNode.id).value;//get pNode's childs
for (var i=0; i<childArray.length; i++) {
n=childArray[i];
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (cn._hc && this.config.preOpenChecked && this.hasCheckedChild(cn)) cn._io = true;
if (!cn._ic && this.config.useCookies && ((this.config.useCheckbox4c && !cn._hc)||(this.config.useCheckbox4p && cn._hc)) && (cn.hasCheckbox )) cn._ic = this.isChecked(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
addNodesb.append(this.node(cn, n));
if (cn._ls) break;
}
return addNodesb.toString();
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var sb= new StringBuilder() ;
sb.append('<div class="dTreeNode">');
sb.append('<table class="dTreeTable" border="0" cellspacing="0" cellpadding="0" ><tr><td>');
sb.append(this.indent(node, nodeId));
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
sb.append('<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '"border = 0 alt="" />');
}
//checkbox
if (((this.config.useCheckbox4c && !node._hc)||(this.config.useCheckbox4p && node._hc))&& (node.hasCheckbox)){
sb.append('</td><td><input type=checkbox id="c' + this.obj + nodeId+'" name="check' + this.obj + '" value="'+node.id+'" ');
if (node._ic) sb.append('checked ');
if (node._ro) sb.append('disabled ');
sb.append('onClick="javascript: ' + this.obj + '.doCheck(' + nodeId + ');"/> ');
}
sb.append('</td><td>');
if (node.url) {
sb.append('<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"');
if (node.title) sb.append(' title="' + node.title + '"');
if (node.target)sb.append(' target="' + node.target + '"');
if (this.config.useStatusText) sb.append(' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ');
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
sb.append(' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"');
sb.append( '>');
}
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
sb.append('<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">');
if(node.isError)
sb.append('<font color=red>'+node.name+'</font>');
else sb.append(node.name);
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) sb.append('</a>');
sb.append('</td></tr></table>');
sb.append('</div>');
if (node._hc) {
sb.append('<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">');
sb.append(this.addNode(node));
sb.append('</div>');
}
this.aIndent.pop();
return sb.toString();
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var subsb= new StringBuilder() ;
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
subsb.append('<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '"border=0 alt="" />');
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
subsb.append('<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '"border=0 src="');
if (!this.config.useLines) subsb.append((node._io) ? this.icon.nlMinus : this.icon.nlPlus);
else subsb.append(( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) ));
subsb.append( '" alt="" /></a>');
} else subsb.append('<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '"border=0 alt="" />');
}
return subsb.toString();
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
if(hashmap.containsKey(node.id)){
var childArray=hashmap.getItem(node.id).value;//get pNode's childs
if(childArray.length>0){
node._hc = true;
}}
var sameParentArray = hashmap.getItem(node.pid).value;
if(sameParentArray.length>0){
var n=sameParentArray[sameParentArray.length-1];
var lastnode = this.aNodes[n];
lastId = lastnode.id;
}
if (lastId==node.id) node._ls = true;
};
// Checks if a node has any children checked
dTree.prototype.hasCheckedChild = function(node){
if(hashmap.containsKey(node.id)){
var childArray=hashmap.getItem(node.id).value;
for(var i=0;i<childArray.length;i++){
var index = childArray[i];
cn = this.aNodes[index];
if (cn.pid == node.id){
if(cn._ic || this.hasCheckedChild(cn)) return true;
}
}}
return false;
}
// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
// Highlights the selected node
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) {
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);
}
};
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// Checks or unchecks a checkbox
dTree.prototype.doCheck = function(id){
var cn = this.aNodes[id];
eCheck =document.getElementById('c'+this.obj+id);
if (eCheck==null)return;
cn._ic = eCheck.checked;
if(this.config.relationCheck){
if (cn._hc && cn._ic) this.checkChild(cn);
if (!cn._ic) this.uncheckParent(cn);
if(cn._hc&&(!cn._ic)) this.unCheckChild(cn);
}
if (this.config.useCookies) {
this.retainChecked();
}
}
// Checks children of a specific node
dTree.prototype.checkChild = function(pNode){
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
eCheck = document.getElementById('c'+this.obj+n);
if (eCheck==null)continue;
cn._ic = true;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.checkChild(this.aNodes[n])
}
if (cn._ls) continue;
}
}
}
//unchecks children of a specific node
dTree.prototype.unCheckChild = function(pNode){
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
eCheck = document.getElementById('c'+this.obj+n);
if (eCheck==null)continue;
cn._ic = false;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.unCheckChild(this.aNodes[n])
}
if (cn._ls) continue;
}
}
}
// Unchecks parent nodes of a specific node
dTree.prototype.uncheckParent = function(cNode){
if (cNode.pid==this.root.id || !cNode._p) return;
cn = cNode._p;
eCheck = document.getElementById('c'+this.obj+cn._ai);
if (eCheck==null)return;
cn._ic = false;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.uncheckParent(cn);
}
}
// Opens or closes all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
// Opens the branches of the checked nodes
dTree.prototype.openChecked = function(){
for (var n=0; n<this.aNodes.length; n++) {
cn = this.aNodes[n];
if (cn._ic){
while (cn._p && cn.pid!=this.root.id && !cn._io){
cn=cn._p;
cn._io = true;
if (this.completed) this.nodeStatus(true, cn._ai, cn._ls);
}
}
}
}
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};
// Opens a specific branch
dTree.prototype.openBranch = function(nId) {
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
pNode=cn._p;
pNode._io = true;
if (this.completed) this.nodeStatus(true, pNode._ai, pNode._ls);
if (this.config.useCookies) this.updateCookie();
this.openBranch(pNode._ai);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
this.setCookie('cc'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var sb = new StringBuilder();
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io ) {
if (sb.toString()) sb.append( '.');
sb.append(this.aNodes[n].id);
}
}
this.setCookie('co' + this.obj, sb.toString());
};
// [Cookie] Store ids of checked nodes in a cookie
dTree.prototype.retainChecked = function() {
var sb = new StringBuilder();
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._ic ) {
if (sb.toString()) sb.append( '.');
sb.append(this.aNodes[n].id);
}
}
this.setCookie('cc' + this.obj, sb.toString());
};
// [Cookie] Checks if a node id is open
dTree.prototype.isOpen = function(id) {
var str = this.getCookie('co' + this.obj);
if (str=='')return false;
var aOpen = str.split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};
// [Cookie] Checks if a node is checked
dTree.prototype.isChecked = function(id){
var str = this.getCookie('cc' + this.obj);
if (str=='')return false;
var aChecked = str.split('.');
for (var n=0; n<aChecked.length; n++)
if (aChecked[n] == id) return true;
return false;
}
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};
在使用的时候,根据dtree的构造函数来创建树。树的节点内容通过ajax动态地从数据库中存取。
举个例子:
aTree = new dTree('aTree','/pm/skins/common/image/dtree/',checkFun);
//checkFun是一个js的函数。
增加节点:
aTree.add("loadr"+pId,pId,'load……',false,false,false,searchTxt.length>0,'','','',empGif,empGif);
aTree.add("e"+divItem.id,pId,divItem.name,true,divItem.selected,false,searchTxt.length>0,'','','',empGif,empGif);
下面是dtree.js中的内容。这个dtree中节点带有复选框。
function StringBuilder() {//add a function to increase speed
this.__strings__ = new Array;
}
StringBuilder.prototype.append = function (str) {
this.__strings__.push(str);
};
StringBuilder.prototype.toString = function () {
return this.__strings__.join("");
};
var hashmap=new Hash();
function Node(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen,isError) {
this.id = id;
this.pid = pid;
this.name = name;
this.url = url;
this.title = title;
this.target = target;
this.icon = icon;
this.iconOpen = iconOpen;
this.isError = isError;
this._io = open || false;
this._is = false;
this._ls = false;
this._hc = false;
this._ai = 0;
this._p;
this._ic = check || false;
this._ro= readOnly || false;
this.hasCheckbox = hasCheckbox;
};
// Tree object
function dTree(objName,imageUrl) {
if (imageUrl==null) imageUrl = '/skins/default/images/treeimages/';
if (objName==null) objName = 'Tree';
this.config = {
target : null,
folderLinks : true,
useSelection : true,
useCookies : true,
useLines : true,
useIcons : false,
useStatusText : false,
closeSameLevel : false,
inOrder : false,
useCheckbox4c :true,
useCheckbox4p :true,
preOpenChecked:true
,
relationCheck:true //是否加载父子的check关系,比如check父的时候所有子节点被check
}
this.icon = {
root : imageUrl+'base.gif',
folder : imageUrl+'folder.gif',
folderOpen : imageUrl+'folderopen.gif',
node : imageUrl+'page.gif',
empty : imageUrl+'empty.gif',
line : imageUrl+'line.gif',
join : imageUrl+'join.gif',
joinBottom : imageUrl+'joinbottom.gif',
plus : imageUrl+'plus.gif',
plusBottom : imageUrl+'plusbottom.gif',
minus : imageUrl+'minus.gif',
minusBottom : imageUrl+'minusbottom.gif',
nlPlus : imageUrl+'nolines_plus.gif',
nlMinus : imageUrl+'nolines_minus.gif'
};
this.obj = objName;
this.aNodes = [];
this.aIndent = [];
this.root = new Node(-1);
this.selectedNode = null;
this.selectedFound = false;
this.completed = false;
};
// Adds a new node to the nodes array
dTree.prototype.add = function(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen, isError) {
this.aNodes[this.aNodes.length] = new Node(id, pid, name, hasCheckbox, check, readOnly, open, url, title, target, icon, iconOpen, isError);
if(hashmap.containsKey(pid)){//key:parent id value :array which record childs' id
var arrayValue=hashmap.getItem(pid).value;
arrayValue.push(this.aNodes.length-1);
}else{
var tempArray=new Array();
tempArray.push(this.aNodes.length-1);
hashmap.add(pid,tempArray);
}
};
// Open/close all nodes
dTree.prototype.openAll = function() {
this.oAll(true);
};
dTree.prototype.closeAll = function() {
this.oAll(false);
};
// Outputs the tree to the page
dTree.prototype.toString = function() {
var str = '<div class="dtree">\n';
if (document.getElementById) {
if (this.config.useCookies)this.selectedNode = this.getSelected();
str += this.addNode(this.root);
} else str += 'Browser not supported.';
str += '</div>';
if (!this.selectedFound) this.selectedNode = null;
this.completed = true;
return str;
};
// Creates the tree structure
dTree.prototype.addNode = function(pNode) {
var addNodesb=new StringBuilder();
var n=0;
if (this.config.inOrder) n = pNode._ai;
var childArray=hashmap.getItem(pNode.id).value;//get pNode's childs
for (var i=0; i<childArray.length; i++) {
n=childArray[i];
var cn = this.aNodes[n];
cn._p = pNode;
cn._ai = n;
this.setCS(cn);
if (!cn.target && this.config.target) cn.target = this.config.target;
if (cn._hc && !cn._io && this.config.useCookies) cn._io = this.isOpen(cn.id);
if (cn._hc && this.config.preOpenChecked && this.hasCheckedChild(cn)) cn._io = true;
if (!cn._ic && this.config.useCookies && ((this.config.useCheckbox4c && !cn._hc)||(this.config.useCheckbox4p && cn._hc)) && (cn.hasCheckbox )) cn._ic = this.isChecked(cn.id);
if (!this.config.folderLinks && cn._hc) cn.url = null;
if (this.config.useSelection && cn.id == this.selectedNode && !this.selectedFound) {
cn._is = true;
this.selectedNode = n;
this.selectedFound = true;
}
addNodesb.append(this.node(cn, n));
if (cn._ls) break;
}
return addNodesb.toString();
};
// Creates the node icon, url and text
dTree.prototype.node = function(node, nodeId) {
var sb= new StringBuilder() ;
sb.append('<div class="dTreeNode">');
sb.append('<table class="dTreeTable" border="0" cellspacing="0" cellpadding="0" ><tr><td>');
sb.append(this.indent(node, nodeId));
if (this.config.useIcons) {
if (!node.icon) node.icon = (this.root.id == node.pid) ? this.icon.root : ((node._hc) ? this.icon.folder : this.icon.node);
if (!node.iconOpen) node.iconOpen = (node._hc) ? this.icon.folderOpen : this.icon.node;
if (this.root.id == node.pid) {
node.icon = this.icon.root;
node.iconOpen = this.icon.root;
}
sb.append('<img id="i' + this.obj + nodeId + '" src="' + ((node._io) ? node.iconOpen : node.icon) + '"border = 0 alt="" />');
}
//checkbox
if (((this.config.useCheckbox4c && !node._hc)||(this.config.useCheckbox4p && node._hc))&& (node.hasCheckbox)){
sb.append('</td><td><input type=checkbox id="c' + this.obj + nodeId+'" name="check' + this.obj + '" value="'+node.id+'" ');
if (node._ic) sb.append('checked ');
if (node._ro) sb.append('disabled ');
sb.append('onClick="javascript: ' + this.obj + '.doCheck(' + nodeId + ');"/> ');
}
sb.append('</td><td>');
if (node.url) {
sb.append('<a id="s' + this.obj + nodeId + '" class="' + ((this.config.useSelection) ? ((node._is ? 'nodeSel' : 'node')) : 'node') + '" href="' + node.url + '"');
if (node.title) sb.append(' title="' + node.title + '"');
if (node.target)sb.append(' target="' + node.target + '"');
if (this.config.useStatusText) sb.append(' onmouseover="window.status=\'' + node.name + '\';return true;" onmouseout="window.status=\'\';return true;" ');
if (this.config.useSelection && ((node._hc && this.config.folderLinks) || !node._hc))
sb.append(' onclick="javascript: ' + this.obj + '.s(' + nodeId + ');"');
sb.append( '>');
}
else if ((!this.config.folderLinks || !node.url) && node._hc && node.pid != this.root.id)
sb.append('<a href="javascript: ' + this.obj + '.o(' + nodeId + ');" class="node">');
if(node.isError)
sb.append('<font color=red>'+node.name+'</font>');
else sb.append(node.name);
if (node.url || ((!this.config.folderLinks || !node.url) && node._hc)) sb.append('</a>');
sb.append('</td></tr></table>');
sb.append('</div>');
if (node._hc) {
sb.append('<div id="d' + this.obj + nodeId + '" class="clip" style="display:' + ((this.root.id == node.pid || node._io) ? 'block' : 'none') + ';">');
sb.append(this.addNode(node));
sb.append('</div>');
}
this.aIndent.pop();
return sb.toString();
};
// Adds the empty and line icons
dTree.prototype.indent = function(node, nodeId) {
var subsb= new StringBuilder() ;
if (this.root.id != node.pid) {
for (var n=0; n<this.aIndent.length; n++)
subsb.append('<img src="' + ( (this.aIndent[n] == 1 && this.config.useLines) ? this.icon.line : this.icon.empty ) + '"border=0 alt="" />');
(node._ls) ? this.aIndent.push(0) : this.aIndent.push(1);
if (node._hc) {
subsb.append('<a href="javascript: ' + this.obj + '.o(' + nodeId + ');"><img id="j' + this.obj + nodeId + '"border=0 src="');
if (!this.config.useLines) subsb.append((node._io) ? this.icon.nlMinus : this.icon.nlPlus);
else subsb.append(( (node._io) ? ((node._ls && this.config.useLines) ? this.icon.minusBottom : this.icon.minus) : ((node._ls && this.config.useLines) ? this.icon.plusBottom : this.icon.plus ) ));
subsb.append( '" alt="" /></a>');
} else subsb.append('<img src="' + ( (this.config.useLines) ? ((node._ls) ? this.icon.joinBottom : this.icon.join ) : this.icon.empty) + '"border=0 alt="" />');
}
return subsb.toString();
};
// Checks if a node has any children and if it is the last sibling
dTree.prototype.setCS = function(node) {
var lastId;
if(hashmap.containsKey(node.id)){
var childArray=hashmap.getItem(node.id).value;//get pNode's childs
if(childArray.length>0){
node._hc = true;
}}
var sameParentArray = hashmap.getItem(node.pid).value;
if(sameParentArray.length>0){
var n=sameParentArray[sameParentArray.length-1];
var lastnode = this.aNodes[n];
lastId = lastnode.id;
}
if (lastId==node.id) node._ls = true;
};
// Checks if a node has any children checked
dTree.prototype.hasCheckedChild = function(node){
if(hashmap.containsKey(node.id)){
var childArray=hashmap.getItem(node.id).value;
for(var i=0;i<childArray.length;i++){
var index = childArray[i];
cn = this.aNodes[index];
if (cn.pid == node.id){
if(cn._ic || this.hasCheckedChild(cn)) return true;
}
}}
return false;
}
// Returns the selected node
dTree.prototype.getSelected = function() {
var sn = this.getCookie('cs' + this.obj);
return (sn) ? sn : null;
};
// Highlights the selected node
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) {
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);
}
};
// Toggle Open or close
dTree.prototype.o = function(id) {
var cn = this.aNodes[id];
this.nodeStatus(!cn._io, id, cn._ls);
cn._io = !cn._io;
if (this.config.closeSameLevel) this.closeLevel(cn);
if (this.config.useCookies) this.updateCookie();
};
// Checks or unchecks a checkbox
dTree.prototype.doCheck = function(id){
var cn = this.aNodes[id];
eCheck =document.getElementById('c'+this.obj+id);
if (eCheck==null)return;
cn._ic = eCheck.checked;
if(this.config.relationCheck){
if (cn._hc && cn._ic) this.checkChild(cn);
if (!cn._ic) this.uncheckParent(cn);
if(cn._hc&&(!cn._ic)) this.unCheckChild(cn);
}
if (this.config.useCookies) {
this.retainChecked();
}
}
// Checks children of a specific node
dTree.prototype.checkChild = function(pNode){
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
eCheck = document.getElementById('c'+this.obj+n);
if (eCheck==null)continue;
cn._ic = true;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.checkChild(this.aNodes[n])
}
if (cn._ls) continue;
}
}
}
//unchecks children of a specific node
dTree.prototype.unCheckChild = function(pNode){
var n=0;
if (this.config.inOrder) n = pNode._ai;
for (n; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == pNode.id) {
var cn = this.aNodes[n];
eCheck = document.getElementById('c'+this.obj+n);
if (eCheck==null)continue;
cn._ic = false;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.unCheckChild(this.aNodes[n])
}
if (cn._ls) continue;
}
}
}
// Unchecks parent nodes of a specific node
dTree.prototype.uncheckParent = function(cNode){
if (cNode.pid==this.root.id || !cNode._p) return;
cn = cNode._p;
eCheck = document.getElementById('c'+this.obj+cn._ai);
if (eCheck==null)return;
cn._ic = false;
if(eCheck.checked!=cn._ic)
{
eCheck.checked=cn._ic;
this.uncheckParent(cn);
}
}
// Opens or closes all nodes
dTree.prototype.oAll = function(status) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._hc && this.aNodes[n].pid != this.root.id) {
this.nodeStatus(status, n, this.aNodes[n]._ls)
this.aNodes[n]._io = status;
}
}
if (this.config.useCookies) this.updateCookie();
};
// Opens the branches of the checked nodes
dTree.prototype.openChecked = function(){
for (var n=0; n<this.aNodes.length; n++) {
cn = this.aNodes[n];
if (cn._ic){
while (cn._p && cn.pid!=this.root.id && !cn._io){
cn=cn._p;
cn._io = true;
if (this.completed) this.nodeStatus(true, cn._ai, cn._ls);
}
}
}
}
// Opens the tree to a specific node
dTree.prototype.openTo = function(nId, bSelect, bFirst) {
if (!bFirst) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].id == nId) {
nId=n;
break;
}
}
}
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
cn._io = true;
cn._is = bSelect;
if (this.completed && cn._hc) this.nodeStatus(true, cn._ai, cn._ls);
if (this.completed && bSelect) this.s(cn._ai);
else if (bSelect) this._sn=cn._ai;
this.openTo(cn._p._ai, false, true);
};
// Opens a specific branch
dTree.prototype.openBranch = function(nId) {
var cn=this.aNodes[nId];
if (cn.pid==this.root.id || !cn._p) return;
pNode=cn._p;
pNode._io = true;
if (this.completed) this.nodeStatus(true, pNode._ai, pNode._ls);
if (this.config.useCookies) this.updateCookie();
this.openBranch(pNode._ai);
};
// Closes all nodes on the same level as certain node
dTree.prototype.closeLevel = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.pid && this.aNodes[n].id != node.id && this.aNodes[n]._hc) {
this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Closes all children of a node
dTree.prototype.closeAllChildren = function(node) {
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n].pid == node.id && this.aNodes[n]._hc) {
if (this.aNodes[n]._io) this.nodeStatus(false, n, this.aNodes[n]._ls);
this.aNodes[n]._io = false;
this.closeAllChildren(this.aNodes[n]);
}
}
}
// Change the status of a node(open or closed)
dTree.prototype.nodeStatus = function(status, id, bottom) {
eDiv = document.getElementById('d' + this.obj + id);
eJoin = document.getElementById('j' + this.obj + id);
if (this.config.useIcons) {
eIcon = document.getElementById('i' + this.obj + id);
eIcon.src = (status) ? this.aNodes[id].iconOpen : this.aNodes[id].icon;
}
eJoin.src = (this.config.useLines)?
((status)?((bottom)?this.icon.minusBottom:this.icon.minus):((bottom)?this.icon.plusBottom:this.icon.plus)):
((status)?this.icon.nlMinus:this.icon.nlPlus);
eDiv.style.display = (status) ? 'block': 'none';
};
// [Cookie] Clears a cookie
dTree.prototype.clearCookie = function() {
var now = new Date();
var yesterday = new Date(now.getTime() - 1000 * 60 * 60 * 24);
this.setCookie('co'+this.obj, 'cookieValue', yesterday);
this.setCookie('cs'+this.obj, 'cookieValue', yesterday);
this.setCookie('cc'+this.obj, 'cookieValue', yesterday);
};
// [Cookie] Sets value in a cookie
dTree.prototype.setCookie = function(cookieName, cookieValue, expires, path, domain, secure) {
document.cookie =
escape(cookieName) + '=' + escape(cookieValue)
+ (expires ? '; expires=' + expires.toGMTString() : '')
+ (path ? '; path=' + path : '')
+ (domain ? '; domain=' + domain : '')
+ (secure ? '; secure' : '');
};
// [Cookie] Gets a value from a cookie
dTree.prototype.getCookie = function(cookieName) {
var cookieValue = '';
var posName = document.cookie.indexOf(escape(cookieName) + '=');
if (posName != -1) {
var posValue = posName + (escape(cookieName) + '=').length;
var endPos = document.cookie.indexOf(';', posValue);
if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
else cookieValue = unescape(document.cookie.substring(posValue));
}
return (cookieValue);
};
// [Cookie] Returns ids of open nodes as a string
dTree.prototype.updateCookie = function() {
var sb = new StringBuilder();
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._io ) {
if (sb.toString()) sb.append( '.');
sb.append(this.aNodes[n].id);
}
}
this.setCookie('co' + this.obj, sb.toString());
};
// [Cookie] Store ids of checked nodes in a cookie
dTree.prototype.retainChecked = function() {
var sb = new StringBuilder();
for (var n=0; n<this.aNodes.length; n++) {
if (this.aNodes[n]._ic ) {
if (sb.toString()) sb.append( '.');
sb.append(this.aNodes[n].id);
}
}
this.setCookie('cc' + this.obj, sb.toString());
};
// [Cookie] Checks if a node id is open
dTree.prototype.isOpen = function(id) {
var str = this.getCookie('co' + this.obj);
if (str=='')return false;
var aOpen = str.split('.');
for (var n=0; n<aOpen.length; n++)
if (aOpen[n] == id) return true;
return false;
};
// [Cookie] Checks if a node is checked
dTree.prototype.isChecked = function(id){
var str = this.getCookie('cc' + this.obj);
if (str=='')return false;
var aChecked = str.split('.');
for (var n=0; n<aChecked.length; n++)
if (aChecked[n] == id) return true;
return false;
}
// If Push and pop is not implemented by the browser
if (!Array.prototype.push) {
Array.prototype.push = function array_push() {
for(var i=0;i<arguments.length;i++)
this[this.length]=arguments[i];
return this.length;
}
};
if (!Array.prototype.pop) {
Array.prototype.pop = function array_pop() {
lastElement = this[this.length-1];
this.length = Math.max(this.length-1,0);
return lastElement;
}
};
在使用的时候,根据dtree的构造函数来创建树。树的节点内容通过ajax动态地从数据库中存取。
举个例子:
aTree = new dTree('aTree','/pm/skins/common/image/dtree/',checkFun);
//checkFun是一个js的函数。
增加节点:
aTree.add("loadr"+pId,pId,'load……',false,false,false,searchTxt.length>0,'','','',empGif,empGif);
aTree.add("e"+divItem.id,pId,divItem.name,true,divItem.selected,false,searchTxt.length>0,'','','',empGif,empGif);
发表评论
-
mysql随机获取记录
2012-12-11 12:42 1180MYSQL的随机抽取实现方法。举个例子,要从tablename ... -
分享到微博js
2012-08-02 14:35 10011分享到微博js 1.分享到微博代码: var t ... -
js 定位
2012-02-02 11:31 3086前两天开发一个功能,显示所有记录之后,对某一条记录操作之后, ... -
jstl标签 函数
2012-02-02 11:02 1289jstl标签,fn函数 函数:fn:contains(stri ... -
java.lang.IllegalArgumentException: Failed to parse a valid name/value pair from
2011-11-23 16:48 2418昨天231被封了,所以只能换203的测试库,可是一启动就报错j ... -
JS中setTimeout()的用法详解
2011-11-07 17:20 0setTimeout( ) setTimeout( ) 是 ... -
Spring中的四种声明式事务的配置
2011-10-18 14:15 1005Spring中的四种声明式事务的配置Spring容器中有两种 ... -
事务的传播行为和隔离级别
2011-10-18 11:13 2688一。Spring在TransactionDefi ... -
Spring 利用PropertyPlaceholderConfigurer占位符
2011-10-18 10:54 34661.Spring的框架中,org.springframew ... -
js动态添加删除表格
2011-10-11 15:25 1563//动态添加行 function addRowMx( ... -
Duplicate class/entity mapping com.sitechasia.xinnet.admin.checkip.model.AdmUser
2011-09-19 14:56 2241今天还算有点时间,就同步了一下我工作空间和cvs服务器上的代码 ... -
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape
2011-09-19 10:32 23934java编码解码 前两天修改了个功能,登陆的时候密码为‘% ... -
servlet页面跳转
2011-09-15 17:26 7939昨天晚上在公 ... -
ContentType
2011-08-25 10:14 1077[size=medium]ContentType 属性指定响 ... -
简单的下载例子
2011-08-25 10:07 1361前两天看代码,有一个下载的例子,我觉得写得挺全面 ... -
Spring Quartz定时器
2011-08-23 15:25 1525Spri ... -
java操作Excel(Jakarta_POI)
2011-08-23 14:15 1276一。 Jakarta POI 是一套用于访问微软 ... -
POI类库之工作表中文名乱码问题
2011-08-23 13:52 2083POI类库是JAVA平台下操作EXCEL的类库,功 ... -
cvs.exe [checkout aborted]: connect to scm1.ceopen.cn:2401 failed: 套接字操作尝试一个无法连接
2011-08-12 13:29 1953昨天想在cvs服务器上更新代码,但是一点更新之 ... -
Spring处理lob数据
2011-08-12 11:27 1656在ssh项目中有一个需要上传、下载的功能,并且将图片 ...
相关推荐
本资源提供了dtree库所需的两个关键文件:`dtree.css`和`dtree.js`,以及相关的图标和API文档,帮助开发者更便捷地在项目中集成和使用dtree。 `dtree.css`是CSS样式表文件,它包含了dtree控件的样式定义。这些样式...
【DTREE】是一种数据结构和算法,主要用于组织和表示具有层次关系的数据。在计算机科学中,决策树(Decision Tree)通常被用作机器学习的一种模型,用于分类和回归分析。而这里的"dtree"可能指的是JavaScript中的一...
在本项目"ajax,servlet动态加载dtree"中,我们看到的是利用Ajax技术和Servlet实现dtree(一种树形菜单控件)的动态加载。这个项目可能是一个文件管理系统或者目录浏览应用,其中dtree用于展示文件或目录结构,而...
layui dtree是一款基于layui框架的树形插件,它提供了丰富的功能和良好的用户体验,尤其适用于在Web应用中展示层级关系的数据。在这个场景中,我们看到的"layui dtree树形结构"指的是在用户点击一个文本框时,会弹出...
**dtree+ajax异步加载树详解** 在Web开发中,数据展示往往涉及到大量的层级结构,如文件系统、组织架构等。dtree是一款基于JavaScript的树形控件,它能够帮助开发者实现动态、交互式的树状菜单。而Ajax...
【dtree 树结构 前端】是一种在前端开发中常见的数据展示方式,它用于构建和展现层次化的数据结构,比如文件系统、组织架构或者导航菜单等。在这个主题下,我们将深入探讨dtree的实现原理、前端技术栈以及相关的实践...
【dtree实现的树支持多选】是一种在网页交互中常用的数据展示和操作方式,尤其在数据层级结构复杂时,如文件系统、组织结构或菜单导航等场景。DTree(通常指的是JavaScript实现的树形控件)允许用户通过勾选节点来...
`dtree` 是一种常用于创建可交互的树形结构组件,它允许用户通过单选按钮(radiobox)和复选框(checkbox)进行选择。本文将深入探讨如何使用 `dtree` 来读取这些选择的值,以及如何根据需求进行定制。 首先,`...
**dtree使用说明及示例演示** 在信息技术领域,决策树(Decision Tree,简称dtree)是一种广泛应用的数据挖掘和机器学习算法。它通过构建一种树形结构来模拟一系列的决策过程,每个内部节点代表一个特征,每个分支...
在这个话题中,我们将深入探讨三种特定的树形结构实现:原始dtree、右键dtree以及复选框dtree,这些都是在JavaScript环境下用于创建交互式树形菜单的工具。 首先,原始dtree是最基础的形式,它通常基于HTML、CSS和...
`dTree` 是一个JavaScript对象,专用于构建无限级的树形菜单。本篇文章将深入探讨如何利用`dTree`来生成动态的树形菜单,并结合后台Action中的List数据进行操作。 首先,我们需要理解`dTree`的基本概念。`dTree`是...
**dtree与dtree_checkbox: JS控件的深入解析** 在网页开发中,交互性和用户体验是至关重要的元素,而JavaScript(简称JS)作为客户端脚本语言,为实现这些功能提供了强大的支持。在这个话题中,我们将重点探讨两种...
在"json+dtree定时刷新dtree"这个主题中,我们主要关注的是如何利用JSON数据与DTREE控件结合,并实现定时刷新功能。定时刷新功能常用于实时更新显示的数据,例如监控系统、数据统计分析等场景,确保用户能够看到最新...
dTree.js是一款轻量级的JavaScript库,专门用于在网页中创建交互式的树形结构,如目录树或数据层级展示。这个压缩包包含了dTree.js的实现文件以及相关的API文档和示例,可以帮助开发者快速理解和使用这个库。 首先...
通过以上介绍,我们可以看到【带节点点击事件的DTree】是一个强大且灵活的前端组件,它结合了树形结构、事件处理和动态数据加载等多种功能,为开发人员提供了构建交互式界面的有效工具。在实际项目中,开发者可以...
【标题】: "dtree.zip" 是一个包含与决策树(Decision Tree)相关的资源的压缩文件,可能是一个用于展示或教学决策树算法的项目。 【描述】: "dtree.zip" 提供了多个文件,包括样式表(dtree.css)、API文档(api....
### 动态增强dtree库的关键知识点解析 #### 一、背景介绍 在现代Web开发中,树形结构(如组织架构、文件目录等)是非常常见的数据展示方式。dtree作为一个轻量级的JavaScript插件,被广泛用于构建这类结构。然而,...
在Java Web开发中,`dtree`通常指的是一个JavaScript库,用于创建可交互的树状菜单,常被用于展示层级关系的数据,如目录结构、组织架构等。在JSP(JavaServer Pages)中使用`dtree`,可以增强用户界面的交互性。...
在IT领域,决策树(Decision Tree,简称dtree)是一种常用的数据挖掘和机器学习算法,它通过构建树状模型来解决分类和回归问题。在这个场景中,提到的"dtree支持动态添加、删除节点"意味着该决策树实现允许在构建...