views:

22

answers:

0

A tree is formed from a 2-d javascript array. The first dimension is the no of levels in the tree (vertical) and the second dimension is the the no of nodes in each level.Every node in the tree has got a check box.A node will be shown as checked if all its children are checked.All that code is written.

Now, if some nodes in the tree are checked, I need to show all the nodes that are both selected && more inclusive (if a node at level n is selected dont count all its children as selected) with its parent. How ?

dTree.prototype.showSelected = function(currentLevel,currentParent){
alert('inside showSelected ' + 'level ' + (currentLevel+1) + ' its length ' + this.levelsArray[currentLevel].length);
var str='';
if(this.levelsArray && 
         this.levelsArray[currentLevel].length >0)
{
    for(v=0;v<this.levelsArray[currentLevel].length;v++)
    {
        var currentNodeIndex = this.levelsArray[currentLevel][v];
        alert('checking for --> ' + this.aNodes[currentNodeIndex].name);
        var tempChId = 'ch'+currentNodeIndex;
        alert('tempChId ' + tempChId);
        if(document.getElementById(tempChId).checked)
        {
            alert('checked');
            str+=' text ' + this.aNodes[currentNodeIndex].name + ' level ' + (currentLevel+1) 
                                + ' parent ' + this.aNodes[currentParent].name + '\n';
            alert('str ' + str);
        }else{
            alert('not checked ' + ' sending -> ' + this.aNodes[currentNodeIndex].name + ' as parent' );
            this.showSelected(currentLevel+1,this.aNodes[currentNodeIndex].id);
        }
    }
}else{
    alert('str ' + str);
}
//return str;

}

aNodes is the array holding all the node objects of the Tree. levelsArray is the 2-d array holding all the node indexes (of the aNodes array) of the nodes with level information. Eg:levelsArray[0] is the first Level of the Tree.

Can you please help me with some clue to achieve this?