flex tree的相应操作

本文介绍了一个使用FlexTree组件实现的树形结构应用案例,详细展示了如何通过简单的代码实现树节点的展开、关闭、添加和删除等功能。该示例采用静态数据进行演示,未涉及实际的数据删除操作。

1. /*=========flex tree的展开,关闭,添加、删除子节点=========*/ 2. /*=========因为用的静态数据,所以并没有真正的删除=========*/ 3. <?xml version="1.0" encoding="utf-8"?> 4. <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.*"> 5. <mx:Tree x="10" y="10" width="199" height="327" labelField="@label" id="tree" 6. creationComplete="load()" fontSize="14"></mx:Tree> 7. 8. <mx:XMLList id="treeData"> 9. <node label="Mail Box" id="1"> 10. <node label="Inbox" id="101"> 11. <node label="Marketing" id="10101"/> 12. <node label="Product Management" id="10102"/> 13. <node label="Personal" id="10103"/> 14. </node> 15. <node label="Outbox" id="2"> 16. <node label="Professional" id="201"/> 17. <node label="Personal" id="202"/> 18. </node> 19. <node label="Spam" id="3"/> 20. <node label="Sent" id="4"/> 21. </node> 22. </mx:XMLList> 23. 24. <mx:Script> 25. <!--[CDATA[ 26. import mx.controls.Alert; 27. //加载树数据源 28. private function load():void{ 29. tree.dataProvider=treeData; 30. 31. } 32. //展开所有节点 33. private function expandAll():void{ 34. tree.expandChildrenOf(tree.selectedItem,true); 35. 36. } 37. //关闭所有节点 38. private function closeAll():void{ 39. tree.openItems=[]; 40. } 41. //添加子节点 42. private function addNode():void{ 43. var xml:XML=tree.selectedItem as XML; 44. xml.appendChild("hello"); 45. 46. } 47. //删除子节点 48. private function delNode():void{ 49. tree.dataDescriptor.removeChildAt(tree.selectedItem.parent(),tree.selectedItem,tree.selectedItem.childIndex(),tree.dataProvider); 50. } 51. 52. ]]--> 53. </mx:Script> 54. <mx:Button x="242" y="28" label="添加节点" fontSize="14" click="addNode()"/> 55. <mx:Button x="242" y="69" label="删除节点" fontSize="14" click="delNode()"/> 56. <mx:Button x="242" y="115" label="展开节点" fontSize="14" click="expandAll()"/> 57. <mx:Button x="242" y="156" label="收回节点" fontSize="14" click="closeAll()"/> 58. </mx:Application>

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值