@import url(http://www.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
//驗證并更新此對象的屬性和布局
Tree.validateNow();
for each (var item:Object in Tree.dataProvider)
{
//打開或關閉指定項目下的所有樹項目。如果設置 dataProvider 之后立即調用 expandChildrenOf(),則您可能看不到正確的行為。您應該等待對組件進行驗證或調用 validateNow() 方法。
Tree.expandChildrenOf(item, true);}

第二種方式


 1
 <?xml version="1.0" encoding="utf-8"?>
 2 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
 3                xmlns:s="library://ns.adobe.com/flex/spark" 
 4                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
 5                creationComplete="onInit()">
 6     <fx:Declarations>
 7         <!-- 將非可視元素(例如服務、值對象)放在此處 -->
 8         
 9         <fx:XML id="xml" xmlns="">
10             <node id="#" label="所有">
11                 <node id="101" label="Name101">
12                     <node id="10101" label="Name10101"/>
13                     <node id="10102" label="Name10102"/>
14                     <node id="10103" label="Name10103"/>
15                 </node>
16                 <node id="102" label="Name102">
17                     <node id="10201" label="Name10201"/>
18                     <node id="10202" label="Name10202"/>
19                 </node>
20                 <node id="103" label="Name103">
21                     <node id="10301" label="Name10301"/>
22                 </node>
23             </node>
24         </fx:XML>
25     </fx:Declarations>
26     
27     <fx:Script>
28         <![CDATA[
29             private function onInit():void{
30                 tree.selectedIndex=0;
31                 tree.callLater(expand,null);
32             }
33             private function expand():void{
34                 tree.expandItem(tree.selectedItem,true);
35                 //這里可以隨便指定展開的節點,如果超出默認展開最后一個根節點
36                 tree.selectedIndex=1;
37                 tree.expandItem(tree.selectedItem,true);
38             }
39         ]]>
40     </fx:Script>
41     <mx:Tree id="tree" x="73" y="36" width="200" height="217" dataProvider="{xml}" labelField="@label"></mx:Tree>
42 </s:Application>
43