var branch1 = new branch('branch1','javascript参考书'); 
branch1生成了么?

解决方案 »

  1.   

    你可以在branch和leaf的构造函数里面加个指针指向父节点,而不是加获取父节点的函数在生成branch或者leaf时把父节点作为参数传入如
    function branch(id, text, checked,pNode){ 
            this.id = id; 
            this.text = text; 
            this.add = addLeaf; 
            this.leaves = new Array(); 
            this.write = writeBranch; 
            this.getChildren = getChildren; 
            //this.getParent = getParent(id); 
    //===>
            this.parentNode=pNode;
            this.checked = checked; 
    } var myTree = new tree(); 
    var branch1 = new branch('branch1','javascript参考书',myTree); 
      

  2.   

    上班不能使用qq,下班了又没空使用qq,嘿嘿