文章分类 Classification
Flex3.0入门课程:添加和删除Tree控件节点
稿件来源: 阳光企业网站管理系统 撰稿作者: 太阳光 发表日期: 2013-09-18 阅读次数: 106 查看权限: 游客查看
Flex3.0入门课程:添加和删除Tree控件节点
xml_tree.mxml
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="12"> <mx:Script> <![CDATA[ import mx.collections.XMLListCollection; [Bindable] private var company:XML = <list> <department name="部门A"> <employee name="小A" /> <employee name="小B" /> </department> <department name="部门B"> <employee name="小C" /> <employee name="小D" /> </department> <department name="部门C"> <employee name="小D" /> <employee name="小E" /> </department> </list>; [Bindable] private var companyData:XMLListCollection = new XMLListCollection(company.department); //实现添加节点 private function addNode():void{ //新建节点 var newNode:XML = <employee/>; newNode.@name = empName.text; //添加节点 var xml:XML = XML(tree.selectedItem); if(xml.length()>0){ xml[0].appendChild(newNode); } } //实现删除节点 private function removeNode():void{ var node:XML = XML(tree.selectedItem); //不能删除空节点和部门 if(node == null || node.localName()=="department") return; //获取当前节点的父节点下所有子节点 var children:XMLList = XMLList(node.parent()).children(); //将其转为XMLListCollection var childrenCol:XMLListCollection = new XMLListCollection(children); //获取选中节点的索引,并删除该节点 var i:Number = childrenCol.getItemIndex(node); childrenCol.removeItemAt(i); } ]]> </mx:Script> <mx:Panel width="300" height="300" title="实现添加和删除节点" verticalAlign="middle" horizontalAlign="center"> <mx:Tree id="tree" dataProvider="{companyData}" labelField="@name" width="230" height="200" /> <mx:HBox> <mx:TextInput id="empName" width="60" text="新节点名"/> <mx:Button label="添加节点" click="addNode()"/> <mx:Button label="删除节点" click="removeNode()"/> </mx:HBox> </mx:Panel> </mx:Application>
关键词: Flex3.0,入门课程,tree 编辑时间: 2013-09-18 17:59:18
0
高兴0
支持0
搞笑0
不解0
谎言0
枪稿0
震惊0
无奈0
无聊0
反对0
愤怒
0%(0)
0%(0)
- 暂无评论
文章图片 article Pictrue
网友评论