flex tree的展开,关闭,添加、删除子节点

/*=========flex tree的展开,关闭,添加、删除子节点=========*/
/*=========因为用的静态数据,所以并没有真正的删除=========*/
<?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>



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/xuhuanchao/archive/2009/10/21/4706715.aspx
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值