Flex中如何通过给openItems属性,设置一个XMLList或Array对象来打开Tree的一个节点

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. private function openAllNodes():void {
  9. tree.openItems = dp..node;
  10. }
  11. private function closeAllNodes():void {
  12. tree.openItems = [];
  13. }
  14. ]]>
  15. </mx:Script>
  16. <mx:XMLid="dp">
  17. <root>
  18. <nodelabel="Parent 1">
  19. <nodelabel="Child 1" />
  20. <nodelabel="Child 2">
  21. <nodelabel="Grandchild 1" />
  22. <nodelabel="Grandchild 2" />
  23. </node>
  24. <nodelabel="Child 3" />
  25. <nodelabel="Child 4" />
  26. </node>
  27. </root>
  28. </mx:XML>
  29. <mx:ApplicationControlBardock="true">
  30. <mx:Buttonlabel="Open all nodes" click="openAllNodes();" />
  31. <mx:Buttonlabel="Close all nodes" click="closeAllNodes();" />
  32. </mx:ApplicationControlBar>
  33. <mx:Treeid="tree"
  34. dataProvider="{dp}"
  35. showRoot="false"
  36. labelField="@label"
  37. width="200"/>
  38. </mx:Application>

你可能感兴趣的:(xml,Flex,Adobe)