flex4 中用ArrayCollection来当作tree的数据源示例

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
                                           xmlns:s="library://ns.adobe.com/flex/spark"
                                           xmlns:mx="library://ns.adobe.com/flex/mx"
                                           creationComplete="windowedapplication1_creationCompleteHandler(event)">
        <fx:Script>
                <![CDATA[
                        import mx.collections.ArrayCollection;
                        import mx.events.FlexEvent;
                        import mx.events.ListEvent;

                        [Bindable]
                        private var arr:ArrayCollection=new ArrayCollection();

                        protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
                        {
                                arr=new ArrayCollection();
                                arr.addItem({label: "第一章",children: "还不错哦",data: "哈哈"});
                                arr.addItem({label: "第二章",data: "好样的",children: [{label: "月亮",data: 111},{label: "太阳",data: 222},{label: "火星",data: 333}]});
                                arr.addItem({label: "第三章",data: "嗯嗯",children: "美国是垃圾"});
                        }

                        protected function tree1_changeHandler(event:ListEvent):void
                        {
                                if (tree.selectedItem.hasOwnProperty("data"))
                                {
                                        trace(tree.selectedItem.data);
                                }
                                else
                                {
                                        trace(tree.selectedItem);
                                }
                        }
                ]]>
        </fx:Script>
        <fx:Declarations>
                <!-- 将非可视元素(例如服务、值对象)放在此处 -->
                <fx:XMLList id="treeData">
                        <node label="Mail Box">
                                <node label="123213123123"/>
                        </node>
                        <node label="InBox">
                                <node label="12312312312312"/>
                                <node label="123555555652312312"/>
                                <node label="1231236555555512312"/>
                        </node>
                </fx:XMLList>
        </fx:Declarations>
        <mx:Tree id="tree"
                         x="98"
                         y="19"
                         change="tree1_changeHandler(event)"
                         width="529"
                         height="450"
                         dataProvider="{arr}"
                         labelField="label">
        </mx:Tree>
</s:WindowedApplication>

相关文章

一:display:flex布局display:flex是一种布局方式。它即可以...
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何...
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些...
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周...
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后...
我在网页上运行了一个Flex应用程序,我想使用Command←组合键...