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

Javascript
base64编码/解码
数字日期转化为汉字日期格式
事件驱动的JScript面对象编程
计算24点
事件驱动的JScript面对象编程(例)
JavaScript基础实例:如何计算24点
删除数组元素.
用Javascript写的一个映射表类
JavaScript通用库(一)
TreeView(扩充XMLSelTree)(二)
如何在网页中调试JavaScript
可编辑的 HTML JavaScript 表格控件 DataGrid
JavaScript学习:删除数组元素
JavaScript数字日期转化为汉字日期格式
在网页中控制wmplayer播放器
排序Select中Option项的一个示例
可编辑的 HTML JavaScript 表格控件 DataGrid II
让网页自动穿上外套
javascript表单之间的数据传递!
用Javascript写的一个映射表(MAP)类--续

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-10   浏览: 235 ::
收藏到网摘: 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;
}