Flex中如何通过ComboBox对Tree中介点进行选择展开处理的例子
By Minidxer | December 25, 2008
接下来的例子演示了Flex中如何通过ComboBox,对Tree中介点进行选择展开处理。
让我们先来看一下Demo(可以右键View Source或点击这里察看源代码):
下面是完整代码(或点击这里察看):
Download: main.mxml
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- import mx.events.ListEvent;
- private function comboBox_change(evt:ListEvent):void {
- var team:String = ComboBox(evt.currentTarget).selectedItem.@label;
- var node:XMLList = mlb.league.division.team.(@label == team);
- expandParents(node[0]);
- tree.selectedItem = node[0];
- var idx:int = tree.getItemIndex(node[0]);
- tree.scrollToIndex(idx);
- }
- private function expandParents(node:XML):void {
- if (node && !tree.isItemOpen(node)) {
- tree.expandItem(node, true);
- expandParents(node.parent());
- }
- }
- ]]>
- </mx:Script>
- <mx:XML id="mlb" source="mlb.xml" />
- <mx:ApplicationControlBar dock="true">
- <mx:ComboBox id="comboBox"
- prompt="Please select a team..."
- dataProvider="{mlb.league.division.team}"
- labelField="@label"
- change="comboBox_change(event);" />
- </mx:ApplicationControlBar>
- <mx:Tree id="tree"
- dataProvider="{mlb}"
- labelField="@label"
- showRoot="false"
- width="300"
- rowCount="8" />
- </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子
Topics:
Tree |
No Comments » |
726 views
Tags: expandItem, getItemIndex, isItemOpen, scrollToIndex(), Tree.