当前位置: 首页 > 图文教程 > 网络编程 > Javascript > 关于javascript树形结构的编写问题

Javascript
扩展String功能方法
如何实现JS函数的重载
兼容低版本IE的JScript5.5实现
prototype.js的Ajax对象
Valerio 发布了 Mootools
理解JavaScript中的事件
Popup对象实现右键菜单
HTML DOM Viewer
页面内查找
浅谈JavaScript中面向对象技术的模拟
初学prototype,发个JS接受URL参数的代码
关于Blog顶部的滚动导航条代码
静态页面的值传递(三部曲)
[原创]防止网站内容被小偷采集的js代码
在线游戏大家来找茬II
图片预载入
滚动经典最新话题[prototype框架]下编写
一个对于Array的简单扩展
Array对象方法参考
为数据添加append,remove功能

Javascript 中的 关于javascript树形结构的编写问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 303 ::
收藏到网摘: n/a

function branch(id, text){
this.id = id;
this.text = text;
this.write = writeBranch;
this.add = addLeaf;
this.leaves = new Array();
this.getid=getid;
}
function getid(){return this.id;}

function addLeaf(leaf){
this.leaves[this.leaves.length] = leaf;
}

function writeBranch(){
var branchString =
'< span class="branch" ' + onClick="showBranch(this.getid())"';

//编译的时候出现了this.getid()必须要赋予一个变量的问题,也就是左值问题

求教!!!!!!!!
branchString += '>< img src="plus.gif" id="I' + this.id + '">' + this.text;
branchString += '< /span>';
branchString += '< span class="leaf" id="';
branchString += this.id + '">';
var numLeaves = this.leaves.length;
for (var j=0;j< numLeaves;j++) branchString += this.leaves[j].write();
branchString += '< /span>';
return branchString;
}