flex tree 绑定数据

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

1:xmlist 绑定

<?xml version="1.0" encoding="utf-8"?>
<!-- Tree control example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            [Bindable]
            public var selectedNode:XML;

            // Event handler for the Tree control change event.
            public function treeChanged(event:Event):void {
                selectedNode=Tree(event.target).selectedItem as XML;
            }
        ]]>
    </mx:Script>

    <mx:XMLList id="treeData">
        <node label="Mail Box">
            <node label="Inbox">
                <node label="Marketing"/>
                <node label="Product Management"/>
                <node label="Personal"/>
            </node>
            <node label="Outbox">
                <node label="Professional"/>
                <node label="Personal"/>
            </node>
            <node label="Spam"/>
            <node label="Sent"/>
        </node>    
    </mx:XMLList>

    <mx:Panel title="Tree Control Example" height="75%" width="75%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

        <mx:Label width="100%" color="blue" 
            text="Select a node in the Tree control."/>

        <mx:HDividedBox width="100%" height="100%">
            <mx:Tree id="myTree" width="50%" height="100%" labelField="@label"
                showRoot="false" dataProvider="{treeData}" change="treeChanged(event)"/>
            <mx:TextArea height="100%" width="50%"
                text="Selected Item: {selectedNode.@label}"/>
        </mx:HDividedBox>
        
    </mx:Panel>
</mx:Application>

 

 

2:ArrayCollection 绑定

[Bindable]
private var treeDate:XMLList=new XMLList();

private function onGetModouleHelpInfo(mEvt:JAEvent):void

{

   treeDate=GetTreeXMl(ReportAC);
  

}
public
function GetTreeXMl(mValue:ArrayCollection):XMLList { var result:XML=new XML('<root/>'); result=GetXML(mValue,"0",result) return result.children() } private function GetXML(mValue:ArrayCollection,mParentNode:String,mXML:XML):XML { var result:XML=mXML; if(mValue==null) { return result; } for(var i:int=0;i<mValue.list.length;i++) { if(mValue[i].ParentNode==mParentNode) { var xmlNode:XML; xmlNode=GetTreeNode(mValue[i]); var node:String=mValue[i].Name; mValue.removeItemAt(i); i--; xmlNode=GetXML(mValue,node,xmlNode); result.appendChild(xmlNode); } } return result; } private function GetTreeNode(mValue:Object):XML { var node:XML=new XML("<node/>"); node.@Label=mValue.ChinaName; node.@Help=mValue.Help; node.@ParentNode=mValue.ParentNode; node.@Node=mValue.Name; return node; }

 <mx:Tree id="treList" labelField="@Label"  height="100%" width="100%"
             
   dataProvider="{treeDate}"   change="selectAC(event)"   />

 

转载于:https://www.cnblogs.com/zxh1141/p/3240705.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值