詳細請看:http://www.k-zone.cn/zblog/post/flash-builder-gumbo-bidirectional-bindings.html
本篇文章是《Flash Builder 4 beta (Gumbo) UI、功能的新體驗》第四篇文章,着重介紹的Flex SDK 4(Gumbo)新增加的功能:雙向綁定( bidirectional bindings)
關於《Flash Builder 4 beta (Gumbo) UI、功能的新體驗》系列文章請看:
http://www.k-zone.cn/zblog/catalog.asp?tags=FB4%E6%96%B0%E4%BD%93%E9%AA%8C
okay,通過以下幾個例子來說明什麼是雙向綁定( bidirectional bindings)
我有兩個TextInput的組件,現在想要如下的結果,當對第一個組件賦值後,第二個組件也會被賦值,即這兩個組件的值應該是相等的。
Flex SDK 4(Gumbo)以前的做法:
<!-- Specify data binding for both controls. -->
<mx:TextInput id="input1" text="{input2.text}"/>
<mx:TextInput id="input2" text="{input1.text}"/>
Flex SDK 4(Gumbo)的做法:
<mx:TextInput id="input1" text="@{input2.text}"/>
<mx:TextInput id="input2"/>
第三種做法,使用<fx:Binding>:
<fx:Binding source="input1.text" destination="input2.text" twoWay="true"/>
注意一下紅色的地方,這個地方的寫法就是雙向綁定( bidirectional bindings)的寫法了。
雖然雙向綁定( bidirectional bindings)可以給我們帶來很多便利的方式,但是這個方式也不是萬能的。
以下說明了在什麼場合下無法使用雙向綁定(bidirectional bindings):
1、Style properties(組件的style屬性)
2、Effect properties(組件的effect屬性)
3、The request property of the HttpService, RemoteObject, and WebService classes(HttpService, RemoteObject, and WebService的請求屬性)
4、The arguments property of the RemoteObject class(RemoteObject的參數)
以上四種情況下,雙向綁定( bidirectional bindings)是無法使用的。
以上就是關於雙向綁定( bidirectional bindings)的一些知識點了,希望對各位有用:)