<iframe src="http://blog.minidx.com/ext05/defining-a-custom-label-function-on-a-flex-tree-control/main.html" width="550" height="380"></iframe>
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml"
- layout="vertical"
- verticalAlign="middle"
- backgroundColor="white">
- <mx:Script>
- <![CDATA[
- private function tree_labelFunc(item:XML):String {
- var label:String;
- switch (item.localName()) {
- case "league":
- label = item.@title;
- break;
- case "team":
- label = item.@name;
- break;
- case "stadium":
- label = item.name;
- }
- return label;
- }
- ]]>
- </mx:Script>
- <mx:XMLid="mlb" source="mlb.xml" />
- <mx:Treeid="tree"
- dataProvider="{mlb.league}"
- labelFunction="tree_labelFunc"
- width="300"
- rowCount="8"/>
- </mx:Application>
下面是
Download:
mlb.xml
- <?xml version="1.0" encoding="utf-8"?>
- <mlb>
- <leagueid="al" title="American League">
- <teamname="Baltimore Orioles" />
- <teamname="Boston Red Sox" />
- <teamname="Chicago White Sox" />
- <teamname="Cleveland Indians" />
- <teamname="Detroit Tigers" />
- <teamname="Kansas City Royals" />
- <teamname="Los Angeles Angels of Anaheim" />
- <teamname="Minnesota Twins" />
- <teamname="New York Yankees" />
- <teamname="Oakland Athletics" />
- <teamname="Seattle Mariners" />
- <teamname="Tampa Bay Devil Rays" />
- <teamname="Texas Rangers" />
- <teamname="Toronto Blue Jays" />
- </league>
- <leagueid="nl" title="National League">
- <teamname="Arizona Diamondbacks" />
- <teamname="Atlanta Braves" />
- <teamname="Chicago Cubs" />
- <teamname="Cincinnati Reds" />
- <teamname="Colorado Rockies" />
- <teamname="Florida Marlins" />
- <teamname="Houston Astros" />
- <teamname="Los Angeles Dodgers" />
- <teamname="Milwaukee Brewers" />
- <teamname="New York Mets" />
- <teamname="Philadelphia Phillies" />
- <teamname="Pittsburgh Pirates" />
- <teamname="San Diego Padres" />
- <teamname="San Francisco Giants" />
- <teamname="St. Louis Cardinals" />
- <teamname="Washington Nationals" />
- </league>
- </mlb>