Tree加载时显示所有节点

找了很久的资料,才解决tree加载时显示所有节点这个问题,引自http://hi.baidu.com/lz0830/blog/item/7b406e82d7f41c98f703a632.html

该文中提出Tree的数据源在MXML文件中和数据源是从后台程序获取两种情况:

一、针对第一种情况(tree的数据源在MXML文件中)的写法:

private function initApp():void {
      for each(var item:XML in this.myTree.dataProvider)
           this.myTree.expandChildrenOf(item,true);

}

该函数的调用creationComplete="initApp()"

 

二、数据源从后台程序获取

<!--  读取xml文件给tree绑定数据源 -->
<mx:HTTPService id="tree_httpsrv" url="assets/data/treeview.xml"  result="setTree(event)" fault="faultOperation(event)"  resultFormat="xml" />

<!-- 读取xml文件的处理  -->

[Bindable]
private var tree_xml:XML;

private function setTree(event:ResultEvent):void
{
       tree_xml = XML(event.result);
       var tree_data:XMLList = tree_xml.treeviewNode;
       myTree.dataProvider = tree_data;
       myTree.callLater(expandTree);
}

private function expandTree():void
{
       //expand all tree node
       myTree.expandChildrenOf(tree_xml,true);
}

 

你可能感兴趣的:(html,xml,Blog)