flex 中Tree的数据由数组提供

<?xml version="1.0" encoding="utf-8"?>
<s:BorderContainer xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/mx"
         xmlns:d="http://ns.adobe.com/fxg/2008/dt"
         creationComplete="init()"
         width="100%" height="100%">

 

import mx.controls.*;
import mx.events.*;

import mx.collections.ArrayCollection;

 

[Bindable]

public var treeData:ArrayCollection;

 

<fx:Script>

<![CDATA[

 

private function init():void{

       var ones:Array=new Array();

 

       var one11:Object={label:"tree0",data:"11"};

       ones.push(one11);

 

       var one22:Object={label:"tree1",data:"12"};

       ones.push(one22);

 

      var one33:Object={label:"tree2",data:"13"};

      ones.push(one33);

 

      treeData=new ArrayCollection(ones);

 

      //展开根节点
      //myTree.expandItem(treeData.getItemAt(0), true);
      //设置根节点选中
      //myTree.selectedIndex = 0;

}

 

]]>

</fx:Script>

 

 

<mx:Tree id="myTree"
        width="188" height="455"
        showRoot="false"
        dataProvider="{treeData}"
        labelField="label"
        click="changeEvt(event)"
        x="3" y="205">
    </mx:Tree>

 

</s:BorderContainer>

你可能感兴趣的:(object,tree,Flex,import,library,encoding)