@import url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://www.blogjava.net/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