콤보 박스의 selectedItem 및 value 객체의 필드 중 하나에서 양방향 데이터 바인딩을 활성화해야합니다. @ {variable name} 구조를 사용하고 있습니다.콤보 박스의 selectedItem에 대한 양방향 데이터 바인딩이 Adobe Flex 4에서 @ symbol을 통해 작동하지 않습니다.
값 객체의 필드가 변경되면 콤보 박스의 selectedItem이 업데이트됩니다. 하지만 콤보 상자의 변경 이벤트를 명시 적으로 처리하지 않으면 reverse가 작동하지 않습니다. @가 예상대로 작동하지 않는 이유가 있습니까?
아래 코드에서 OrderInfo.billingName을 combo1.selectedItem에 바인딩하려고합니다.
1을 사용하는 경우 : 경우 OrderInfo.billingName 값은 다음 또한 combo1.selectedItem가 점점 사이에서 변경 : OrderInfo.billingName의 초기 값은
2 유스 케이스을 combo1.selectedItem로 설정지고 업데이트 됨
세 번째 사용 사례 : 사용자가 combo1에서 일부 값을 선택하면 변경 이벤트를 처리하지 않으면 OrderInfo.billingName에 할당되지 않습니다.
public var billingName:String ; //This field is bindable to combo1’s selectedItem
public var billingAddress:String;
public var billingCity:String;
public var billingState:String;
public var billingZip:String;
public var cardType:String;
public var cardNumber:String;
public var cardExpirationMonth:String;
public var cardExpirationYear:String;
public var deliveryDate:Date;
public function OrderInfo() {
}
public function toString():String {
return "I am OrderInfo : " + this.billingName + this.billingCity;
}
}
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955"
minHeight="600"
initialize="application1_initializeHandler(event)">
<fx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
import mx.events.FlexEvent;
import mx.events.IndexChangedEvent;
import mx.utils.ObjectUtil;
import spark.events.IndexChangeEvent;
[Bindable]
public var dp:ArrayCollection = new ArrayCollection (
[ {Id:'one', Amount:1000},
{Id:'two', Amount:2000},
{Id:'three', Amount:3000}
]
);
[Bindable]
public var orderInfo:OrderInfo = new OrderInfo();
protected function application1_initializeHandler(event:FlexEvent):void
{
//Initial value of the field .. this could be coming via database
orderInfo.billingName = 'one';
}
protected function combo1_changeHandler(event:IndexChangeEvent):void
{
orderInfo.billingName = (((event.currentTarget as
ComboBox).selectedItem as Object).Id); //??
}
protected function button1_clickHandler(event:Event):void
{
mx.controls.Alert.show(ObjectUtil.toString(orderInfo));
}
protected function button2_clickHandler(event:Event):void
{
// Some backend process changed the value object
orderInfo.billingName = 'three';
}
]]>
</fx:Script>
<s:ComboBox id="combo1" x="81" y="65"
dataProvider="{dp}"
labelField="Id"
selectedItem="@{orderInfo.billingName}"
change="combo1_changeHandler(event)"
/>
<s:Button label="Get OrderInfo Object Snapshot" click="button1_clickHandler(event)"
x="273" y="176"/>
<s:Button label="Change OrderInfo Object" click="button2_clickHandler(event)"
x="52" y="176"/>