`
it_liuyong
  • 浏览: 98794 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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

    博客分类:
  • flex
 
阅读更多
flex tree的展开,关闭,添加、删除子节点2010-11-12 10:46/*=========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>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics