flex递归树,并添加子节点层次标识

 

public var orgList:ArrayCollection = new ArrayCollection() ;

public var _con:String = ">";   
  public function organResult(e:XML,arr:ArrayCollection = null):void{
   if(_con!=">"){
    orgList.addItem({name:_con + e.@name,id:[email protected]()});
   }
   if (e.children().length() > 0) //获取到根节点下子节点的长度
   {
    _con = "-"+_con; 
    for each (var node:XML in e.children())//遍历子节点
    arguments.callee(node,orgList ); //此举意思是调用自身(递归)   
    //退出子节点的时候把箭头减掉一个
    var index:int=_con.indexOf('-');
    var firstStr:String=_con.substring(0, index);
    var secondStr:String=_con.substring(index + 1, _con.length);
    _con = secondStr;
   }
  }

你可能感兴趣的:(Flex,递归树)