Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted on Aug 27, 2009 05:51
open dhtmlx forum
how to get the list of node parent parent until the final parent (root) is reached?

how to get the list of node parent parent ..... root until the final parent (root) is reached?

i.e. node, nodeparent, nodeparentparent,.....root
Is there any method like getPreProcessingNodes() or postProcessingNOdes()

I have tried this way.......need help regarding

var parentids;
function getListOfParentIds(id,accesslevelids)
    {       
        var parentid=tree.getParentId(id);
        accesslevelids=parentid+","+accesslevelids;
      
        if(parentid!="0")
        getListOfParentIds(parentid,accesslevelids);
        else
        parentids=accesslevelids;
       
        //return ""+accesslevelids;
    }
Actually when i try to return value in else part , it is giving undefined (since the loop is not yet finished, when the result has come)
So, i have taken it in a separate variable "accesslevel".

I need the function itself returning the result, ratherthan taken separately ina  variable.


Answer posted by Alex (support) on Aug 27, 2009 08:00

Try the following approach:

function getParents(id){
  if(id==0){
    parents[parents.length] = tree.getParentId(id);
    getParents(parents[parents.length-1])
    return parents;
  }
}