help me work out this recursive function
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Zhang
Posted On:   Wednesday, November 20, 2002 10:26 AM

I have a treeview like this 001     002         003             004     005         006     007         008         009 I use h_id1,h_id2,h_id3... and h_parent1,h_parent2,h_parent_3....to setup this tree view: h_id h_parent 001 null 002 001 003 002 004 003 005 001 006 005 007 001    More>>

I have a treeview like this


001


    002


        003


            004


    005


        006


    007


        008


        009



I use h_id1,h_id2,h_id3... and h_parent1,h_parent2,h_parent_3....to setup
this tree view:












































h_id h_parent
001 null
002 001
003 002
004 003
005 001
006 005
007 001
008 007
009 007



if I provide an h_id,I need a function gothrough(), to show every one belong
to this h_id, for ex.gothrough(001),it should give me all of h_id from 002 to
009,


I made a recursive function:


function gothrough(parentl){


    for(i=1;i<=len;i++){


        h_parent=eval("document.assoc_form.h_parent"+i).value;


        if (parent==h_parent){


            h_id=eval("document.assoc_form.h_id"+i).value;


           
document.assoc_form.debug.value=document.assoc_form.debug.value +" "+
h_id;


           
gothrough(h_id);  


        }//if


    }//for i


}



but it only give me 002,003,004 in " document.assoc_form.debug ",not
all of them,looks like it go down one branch,but didn't go through the tree,any
body help me fix it


thank you.

   <<Less

Re: help me work out this recursive function

Posted By:   Sujatha_Gopal  
Posted On:   Monday, November 25, 2002 10:14 PM

Try in this way.


Instead of storing only the parent of the node,
Also store one more field h_originator.


In this field store the originator node from which this node came.


Will also tell the end point of the root when traversing back.




Or Else Try using the Tree Traversal Algorithms.
About | Sitemap | Contact