<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="flexlib.controls.*" xmlns:ns2="flexlib.containers.*" width="100%" height="100%" xmlns:commont="commont.*">
<mx:Tree x="10" y="10" width="199" height="327" labelField="@label" id="tree"
creationComplete="load()" fontSize="14"></mx:Tree>
<mx:XMLList id="treeData">
<node label="Mail Box" id="1">
<node label="Inbox" id="101">
<node label="Marketing" id="10101"/>
<node label="Product Management" id="10102"/>
<node label="Personal" id="10103"/>
</node>
<node label="Outbox" id="2">
<node label="Professional" id="201"/>
<node label="Personal" id="202"/>
</node>
<node label="Spam" id="3"/>
<node label="Sent" id="4"/>
</node>
</mx:XMLList>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
//加载树数据源
private function load():void{
tree.dataProvider=treeData;
}
//展开所有节点
private function expandAll():void{
tree.expandChildrenOf(tree.selectedItem,true);
}
//关闭所有节点
private function closeAll():void{
tree.openItems=[];
}
//添加子节点
private function addNode():void{
var xml:XML=tree.selectedItem as XML;
xml.appendChild("hello");
}
//删除子节点
private function delNode():void{
tree.dataDescriptor.removeChildAt(tree.selectedItem.parent(),tree.selectedItem,tree.selectedItem.childIndex(),tree.dataProvider);
}
]]>
</mx:Script>
<mx:Button x="242" y="28" label="添加节点" fontSize="14" click="addNode()"/>
<mx:Button x="242" y="69" label="删除节点" fontSize="14" click="delNode()"/>
<mx:Button x="242" y="115" label="展开节点" fontSize="14" click="expandAll()"/>
<mx:Button x="242" y="156" label="收回节点" fontSize="14" click="closeAll()"/>
</mx:Application>
flex--tree
最新推荐文章于 2022-07-27 09:52:03 发布