Flex Gumbo中如何通过监听selectionChanged事件检测DropDownList被选择项目的例子

By Minidxer | August 9, 2009

接下来的Flex Gumbo中如何通过监听selectionChanged事件,检测DropDownList被选择项目。



下面是main.mxml:

  1. <?xml version="1.0"?>
  2. <s:Application name="Spark_DropDownList_selectionChanged_test"
  3.         xmlns:fx="http://ns.adobe.com/mxml/2009"
  4.         xmlns:s="library://ns.adobe.com/flex/spark"
  5.         xmlns:mx="library://ns.adobe.com/flex/halo">
  6.  
  7.     <fx:Script>
  8.         <![CDATA[
  9.             import mx.events.IndexChangedEvent;
  10.  
  11.             private function dropDownList_selectionChanged(evt:IndexChangedEvent):void {
  12.                 lbl.text = dropDownList.selectedItem.team;
  13.             }
  14.         ]]>
  15.     </fx:Script>
  16.  
  17.     <fx:Declarations>
  18.         <s:ArrayList id="arrList">
  19.             <fx:Object team="Los Angeles" name="Angels of Anaheim" />
  20.             <fx:Object team="Seattle" name="Mariners" />
  21.             <fx:Object team="Oakland" name="Athletics" />
  22.             <fx:Object team="Texas" name="Rangers" />
  23.             <fx:Object team="Cleveland" name="Indians" />
  24.             <fx:Object team="Detroit" name="Tigers" />
  25.             <fx:Object team="Minnesota" name="Twins" />
  26.             <fx:Object team="Chicago" name="White Sox" />
  27.             <fx:Object team="Kansas City" name="Royals" />
  28.             <fx:Object team="Boston" name="Red Sox" />
  29.             <fx:Object team="New York" name="Yankees" />
  30.             <fx:Object team="Toronto" name="Blue Jays" />
  31.             <fx:Object team="Baltimore" name="Orioles" />
  32.             <fx:Object team="Tampa Bay" name="Rays" />
  33.             <fx:Object team="Arizona" name="Diamondbacks" />
  34.             <fx:Object team="Colorado" name="Rockies" />
  35.             <fx:Object team="San Diego" name="Padres" />
  36.             <fx:Object team="Los Angeles" name="Dodgers" />
  37.             <fx:Object team="San Francisco" name="Giants" />
  38.             <fx:Object team="Chicago" name="Cubs" />
  39.             <fx:Object team="Milwaukee" name="Brewers" />
  40.             <fx:Object team="St. Louis" name="Cardinals" />
  41.             <fx:Object team="Houston" name="Astros" />
  42.             <fx:Object team="Cincinnati" name="Reds" />
  43.             <fx:Object team="Pittsburgh" name="Pirates" />
  44.             <fx:Object team="Philadelphia" name="Phillies" />
  45.             <fx:Object team="New York" name="Mets" />
  46.             <fx:Object team="Atlanta" name="Braves" />
  47.             <fx:Object team="Washington" name="Nationals" />
  48.             <fx:Object team="Florida" name="Marlins" />
  49.         </s:ArrayList>
  50.     </fx:Declarations>
  51.  
  52.     <s:VGroup horizontalCenter="0" top="10">
  53.         <s:DropDownList id="dropDownList"
  54.                 dataProvider="{arrList}"
  55.                 labelField="team"
  56.                 prompt="Please select a team..."
  57.                 selectionChanged="dropDownList_selectionChanged(event);" />
  58.         <s:SimpleText id="lbl" />
  59.     </s:VGroup>
  60.  
  61. </s:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: DropDownList, Gumbo | No Comments » | Tags: ,

Search Posts