您的位置:首页 > 其它

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: