flex tree expandItem
2013-06-03 12:47
369 查看
<?xml version="1.0" encoding="utf-8"?>
<!-- http://yecon.blog.hexun.com/30749527_d.html -->
<!-- http://www.slsay.com -->
<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>
<!-- http://yecon.blog.hexun.com/30749527_d.html -->
<!-- http://www.slsay.com -->
<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>
相关文章推荐
- Flex中如何利用expandItem()和expandChildrenOf()展开,或关闭Tree的各层节点
- Opening nodes in a Flex Tree control using the expandItem() method
- [Flex] 组件Tree系列 —— 利用firstVisibleItem属性,设置或取得第一个显示节点
- tree控件----展开树item的函数----CTreeCtrl::Expand
- Flex Tree expandChildrenOf 失效的解决办法
- Using the itemDoubleClick event to open nodes in a Flex Tree control
- Flex Tree 之 TreeItemRenderer
- 【Flex CookBook】TEXT组件添加到一个定制的TreeItemRenderer
- Alternating row colors in a Flex Tree control using the alternatingItemColors style
- Flex Spark DropDownList selectedItem 复制设置(赋值)
- [Flex] Tree控件数据源刷新带来的选中状态问题
- Flex tree增加,删除,查询并定位节点
- FLEX中Tree默认展开所有节点
- Flex中Tree控件的DoubleClick
- flex Tree中的拖放
- Flex 4 List itemClick的实现
- 理解 Flex itemRenderer - 第 2 部分: 外部渲染器
- flex:Tree点击一行打开关闭节点
- Flex中实现Tree绑定数据后自动展开节点
- flex基础之tree组件的使用