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)" />