Flex中如何利用firstVisibleItem属性,设置或取得第一个显示节点

本文介绍了一个使用Adobe Flex框架实现的树状结构组件示例。该示例通过XML定义了数据结构,并利用ComboBox实现了节点的选择功能,同时用Tree组件显示了层次结构。文章展示了如何通过代码实现树节点的展开及滚动到指定节点的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

main.mxml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
  3. layout="vertical"
  4. verticalAlign="middle"
  5. backgroundColor="white">
  6. <mx:Script>
  7. <![CDATA[
  8. import mx.events.FlexEvent;
  9. import mx.events.ListEvent;
  10. private function tree_creationComplete(evt:FlexEvent):void {
  11. tree.expandChildrenOf(xmlDP, true);
  12. }
  13. private function comboBox_change(evt:ListEvent):void {
  14. tree.firstVisibleItem = comboBox.selectedItem;
  15. }
  16. ]]>
  17. </mx:Script>
  18. <mx:XMLid="xmlDP">
  19. <node>
  20. <nodelabel="1.a" />
  21. <nodelabel="1.b" />
  22. <nodelabel="1.c">
  23. <nodelabel="1.c.i" />
  24. <nodelabel="1.c.ii" />
  25. <nodelabel="1.c.iii" />
  26. <nodelabel="1.c.iv" />
  27. <nodelabel="1.c.v" />
  28. </node>
  29. <nodelabel="1.d" />
  30. <nodelabel="1.e">
  31. <nodelabel="1.e.i" />
  32. <nodelabel="1.e.ii" />
  33. <nodelabel="1.e.iii">
  34. <nodelabel="1.e.iii.A" />
  35. </node>
  36. <nodelabel="1.e.iv" />
  37. </node>
  38. <nodelabel="1.f" />
  39. </node>
  40. </mx:XML>
  41. <mx:ApplicationControlBardock="true">
  42. <mx:FormstyleName="plain">
  43. <mx:FormItemlabel="firstVisibleItem:">
  44. <mx:ComboBoxid="comboBox"
  45. dataProvider="{xmlDP..node}"
  46. labelField="@label"
  47. change="comboBox_change(event);"/>
  48. </mx:FormItem>
  49. </mx:Form>
  50. </mx:ApplicationControlBar>
  51. <mx:Treeid="tree"
  52. dataProvider="{xmlDP}"
  53. labelField="@label"
  54. showRoot="false"
  55. alternatingItemColors="[#EEEEEE, #FFFFFF]"
  56. width="50%"
  57. rowCount="6"
  58. creationComplete="tree_creationComplete(event);"/>
  59. </mx:Application>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值