[flex] 组件Tree系列 —— 将数组作为dataProvider

mxml:

<?xml version="1.0" encoding="utf-8"?>

<!--功能描述:将数组作为dataProvider-->

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

    <fx:Script>
        <![CDATA[
            protected function tree_labelFunction(item:Object):String
            {
                var num:String = "";
                if (tree.dataDescriptor.hasChildren(item)) {
                    num = " (" + item.children.length + ")";
                }
                return item.label + num;
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <!-- 将非可视元素(例如服务、值对象)放在此处 -->
        <fx:Array id="data">
            <fx:Object label="周星驰">
                <fx:children>
                    <fx:Object label="1988">
                        <fx:children>
                            <fx:Object label="《霹雳先锋》香港票房8916612" />
                            <fx:Object label="《捕风汉子》香港票房3149395" />
                            <fx:Object label="《最佳女婿》香港票房5807710" />
                        </fx:children>
                    </fx:Object>
                    <fx:Object label="1989">
                        <fx:children>
                            <fx:Object label="《龙在天涯》香港票房6809853 " />
                            <fx:Object label="《义胆群英》香港票房7913329" />
                            <fx:Object label="《流氓差婆》香港票房5624622 " />
                            <fx:Object label="《风雨同路》香港票房9335299 " />

                        </fx:children>
                    </fx:Object>
                </fx:children>
            </fx:Object>
            <fx:Object label="李连杰">
                <fx:children>
                    <fx:Object label="1992">
                        <fx:children>
                            <fx:Object label="笑傲江湖之东方不败(1992)" />
                            <fx:Object label="黄飞鸿之二男儿当自强(1992)" />
                            <fx:Object label="黄飞鸿之三狮王争霸(1992)" />
                        </fx:children>
                    </fx:Object>
                    <fx:Object label="1993">
                        <fx:children>
                            <fx:Object label="方世玉Ⅱ万夫莫敌(1993) " />
                            <fx:Object label="倚天屠龙记之魔教教主(1993)" />
                            <fx:Object label="黄飞鸿之铁鸡斗蜈蚣(1993) " />
                            <fx:Object label="太极张三丰(1993) " />

                        </fx:children>
                    </fx:Object>
                    <fx:Object label="1993">
                        <fx:children>
                            <fx:Object label="新少林五祖(1994) " />
                            <fx:Object label="精武英雄(1994)" />
                            <fx:Object label="中南海保镖(1994)  " />
                            <fx:Object label="给爸爸的信(1995) " />
                        </fx:children>
                    </fx:Object>
                </fx:children>
            </fx:Object>
        </fx:Array>
    </fx:Declarations>

    <mx:Tree id="tree" dataProvider="{data}" labelField="label"  width="320" labelFunction="tree_labelFunction"/>
</s:Application>
时间: 2024-10-04 13:34:46

[flex] 组件Tree系列 —— 将数组作为dataProvider的相关文章

[Flex] 组件Tree系列 —— 运用openItems获取打开节点

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--功能描述:运用openItems获取打开节点--> 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark" 5 xmlns:mx="

[Flex] 组件Tree系列 —— 作为PopUpButton的弹出菜单

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--功能描述:Tree作为PopUpButton的弹出菜单--> 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark" 5 xmlns:mx=&

[Flex] 组件Tree系列 —— 支持CheckBox组件

主程序mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 3 <!--功能描述:支持CheckBox--> 4 5 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 6 xmlns:s="library://ns.adobe.com/flex/spark" 7 xmlns:mx="

[Flex] 组件Tree系列 —— 阻止用户点击选中Tree中任何节点

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--功能描述:阻止用户点击选中Tree中任何节点--> 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark" 5 xmlns:mx="

[Flex] 组件Tree系列 —— 支持元素的拖放排序

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 3 <!--功能描述:支持元素拖放排序--> 4 5 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 6 xmlns:s="library://ns.adobe.com/flex/spark" 7 xmlns:mx="libra

[Flex] 组件Tree系列 —— 运用variableRowHeight和wordWrap设置可变行高

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--功能描述:运用variableRowHeight和wordWrap设置可变行高--> 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark"

[Flex] 组件Tree系列 —— 运用LabelFunction hasChildren getChildren设置Tree包含节点个数

mxml: 1 <?xml version="1.0" encoding="utf-8"?> 2 3 <!--功能描述:运用LabelFunction hasChildren getChildren设置Tree包含节点个数--> 4 5 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 6 xmlns:s="library://ns.adobe.

[Flex] 组件Tree系列 —— 实现右键拓展功能

主程序mxml: <?xml version="1.0" encoding="utf-8"?> <!--功能描述:结合tree拓展右键功能 必须在index.template.html设置params.wmode = "opaque"以屏蔽flash右键;--> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s=&quo

[Flex] 组件Tree系列 —— 打开和关闭节点

mxm: 1 <?xml version="1.0" encoding="utf-8"?> 2 <!--功能描述:打开和关闭节点--> 3 <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 4 xmlns:s="library://ns.adobe.com/flex/spark" 5 xmlns:mx="library://n