我改的一个,或许对你有帮助
注意看expandByClick这个东西
如果某个节点的这个属性为1,则点击该节点打开子节点
//初始化节点信息, 根据 this.nodes 数据源生成节点的详细信息
//sourceIndex 数据源中的父子节点组合的字符串 0_1
//parentId 当前树节点在客户端的父节点的 id
MzTreeView.prototype.nodeInit = function(sourceIndex, parentId)
{
this.index++;
var source= this.nodes[sourceIndex], d = this.divider;
var text = this.getAttribute(source, "text");
var hint = this.getAttribute(source, "hint");
var sid = sourceIndex.substr(sourceIndex.indexOf(d) + d.length);
this.node[this.index] =
{
"id" : this.index,
"text" : text,
"hint" : hint ? hint : text,
"icon" : this.getAttribute(source, "icon"),
"expandByClick": this.getAttribute(source, "expandByClick"),
"path" : this.node[parentId].path + d + this.index,
"isLoad": false,
"isExpand": false,
"parentId": parentId,
"parentNode": this.node[parentId],
"sourceIndex" : sourceIndex,
"childAppend" : ""
};
this.nodes[sourceIndex] = "index:"+ this.index +";"+ source;
this.node[this.index].hasChild = this.names.indexOf(this._d + sid + d)>-1;
if(this.node[this.index].hasChild) this.node[this.index].childNodes = [];
return this.node[this.index];
};.
.
..
.
.
.
.
.
.
.
.//节点链接单击事件处理方法
//id 客户端树节点的 id
MzTreeView.prototype.nodeClick = function(id)
{
if (this.node[id].expandByClick==1)
{
this.expand(id);
} var source = this.nodes[this.node[id].sourceIndex];
eval(this.getAttribute(source, "method"));
return !(!this.getAttribute(source, "url") && this.url=="#");
};
注意看expandByClick这个东西
如果某个节点的这个属性为1,则点击该节点打开子节点
//初始化节点信息, 根据 this.nodes 数据源生成节点的详细信息
//sourceIndex 数据源中的父子节点组合的字符串 0_1
//parentId 当前树节点在客户端的父节点的 id
MzTreeView.prototype.nodeInit = function(sourceIndex, parentId)
{
this.index++;
var source= this.nodes[sourceIndex], d = this.divider;
var text = this.getAttribute(source, "text");
var hint = this.getAttribute(source, "hint");
var sid = sourceIndex.substr(sourceIndex.indexOf(d) + d.length);
this.node[this.index] =
{
"id" : this.index,
"text" : text,
"hint" : hint ? hint : text,
"icon" : this.getAttribute(source, "icon"),
"expandByClick": this.getAttribute(source, "expandByClick"),
"path" : this.node[parentId].path + d + this.index,
"isLoad": false,
"isExpand": false,
"parentId": parentId,
"parentNode": this.node[parentId],
"sourceIndex" : sourceIndex,
"childAppend" : ""
};
this.nodes[sourceIndex] = "index:"+ this.index +";"+ source;
this.node[this.index].hasChild = this.names.indexOf(this._d + sid + d)>-1;
if(this.node[this.index].hasChild) this.node[this.index].childNodes = [];
return this.node[this.index];
};.
.
..
.
.
.
.
.
.
.
.//节点链接单击事件处理方法
//id 客户端树节点的 id
MzTreeView.prototype.nodeClick = function(id)
{
if (this.node[id].expandByClick==1)
{
this.expand(id);
} var source = this.nodes[this.node[id].sourceIndex];
eval(this.getAttribute(source, "method"));
return !(!this.getAttribute(source, "url") && this.url=="#");
};
tree.nodes["0_1"] = "text:WEB 编程;date:id=1;"
来赋值吗?你的"//节点链接单击事件处理方法" 和我用的原理好像大致相同,为什么我的不能实现我的功能呢?
你是怎么测试的呢??这个修改过的树, 我在很多程序里都有在用了
我现在用 method 初步解决了这个问题 不过感觉不是很好,<div id=membermenu style="background-color: "></div>
<script language="JavaScript">
var tree = new MzTreeView("tree");
tree.icons["folder"] = "folder.gif";
tree.iconsExpand["folder"] = "folderopen.gif"; //展开时对应的图片 tree.setIconPath("Tree/"); //可用相对路径
tree.nodes["0_1"] = "text:text;method:reurl(this.node[id],'url.asp?id=1');)";
tree.nodes["0_2"] = "text:text;method:reurl(this.node[id],'url.asp?id=1');)";
tree.nodes["1_3"] = "text:text;method:reurl(this.node[id],'url.asp?id=1');)";
tree.nodes["1_4"] = "text:text;method:reurl(this.node[id],'url.asp?id=1');)"; tree.setTarget("_self");
//document.all.membermenu.innerHTML= tree.toString();
document.write(tree.toString());
function reurl(dip1,dip3){
if (dip1.hasChild){
tree.lowerNode();
}
else{
window.location=dip3
}
}
</script>
应该是说点击的结点是否有子节点吧我对JS也不是很了解,只是能进行一些小修改
现在环境不允许,过几天如果你还需要,我就给你一个example
还有 对于 MzTreeView.prototype.nodeClick = function(id) 这种函数方式 不了解 能不能说一下你的代码中的 var source = this.nodes[this.node[id].sourceIndex];
eval(this.getAttribute(source, "method"));
return !(!this.getAttribute(source, "url") && this.url=="#");我也不理解而且 如果要从数据库中 取出大量数据用 this.node[this.index] ={} 赋值是不是比较麻烦?