Flex中数据ComboBox的绑定的两种方式

Combobox绑定中是否使用dataField

方法一:

<mx:FormItem direction="horizontal" >
  <mx:Label  id="lblFormCity"  text="飞机起飞城市"/><mx:ComboBox id="cboformCity" dataProvider="{citysList.item.@label}"  width="65"/>
</mx:FormItem>

 

方法二:
<mx:FormItem  direction="horizontal">
  <mx:Label  id="lblToCity"  text="飞机到达城市"/><mx:ComboBox id="cbotoCity" dataProvider="{citysList.item}" labelField="@label" width="66"/>
</mx:FormItem>

 

 

实例Demo如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Form xmlns:mx="http://www.adobe.com/2006/mxml"  >
<mx:Script>
 <![CDATA[
    import flash.events.MouseEvent;
    import mx.controls.Alert;
  private function searchHandler():void
  {
     Alert.show("test");
  }
 ]]>
</mx:Script>
<mx:XMLList id="citysList">
  <items>
   <item label="深 圳" value="sz"/>
   <item label="上 海" value="sh"/>
   <item label="天 津" value="tj"/>
  </items>
</mx:XMLList>
<mx:FormItem direction="horizontal" >
  <mx:Label  id="lblFormCity"  text="飞机起飞城市"/><mx:ComboBox id="cboformCity" dataProvider="{citysList.item.@label}"  width="65"/>
</mx:FormItem>
<mx:FormItem  direction="horizontal">
  <mx:Label  id="lblToCity"  text="飞机到达城市"/><mx:ComboBox id="cbotoCity" dataProvider="{citysList.item}" labelField="@label" width="66"/>
</mx:FormItem>
<mx:FormItem direction="horizontal" >
   <mx:Label width="45" id="lblstatDate" text="起飞时间"/><mx:DateField  id="startDate" />
</mx:FormItem>
<mx:FormItem direction="horizontal" >
   <mx:Label width="45" id="lblendDate" text="抵达时间"/><mx:DateField  id="endDate" />
</mx:FormItem>
<mx:FormItem direction="horizontal" width="158">
<mx:ControlBar>
  <mx:RadioButtonGroup id="radwayType"/>
  <mx:RadioButton  width="45" groupName="radwayType" label="单程" value="0" />
  <mx:RadioButton width="45"  groupName="radwayType" label="联程" value="1" />
  <mx:Spacer width="100%"/> 
</mx:ControlBar>
</mx:FormItem>
<mx:FormItem direction="horizontal" textAlign="right" width="159">
   <mx:Button id="searchbtn"  width="45"  label="查  询"  textAlign="center"  click="searchHandler()"    />
</mx:FormItem>
</mx:Form>

 

简简单单的哦哈哈

你可能感兴趣的:(xml,Flex,Flash,Adobe)