Flex 動態綁定BindingUtils.bindProperty

來源:互聯網
上載者:User

關鍵字:BindingUtils.bindProperty
需匯入:import mx.binding.utils.BindingUtils;
/**
* 動態綁定
* @params site:Object 被綁定對象
* @params prop:String 被綁定對象的屬性,如textInput的text屬性
* @params host:Object 監視者對象
* @params chain:Object 監視者對象的屬性
* @return ChangeWatcher
* **/
BindingUtils.bindProperty(site:Object,prop:String,host:Object,chain:Object); 複製代碼 代碼如下:<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" initialize="init();">

<mx:Script>
<!--[CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;

private var watcher1:ChangeWatcher;
private var watcher2:ChangeWatcher;

/**
* 動態綁定
* @return void
* **/
private function Binding():void {

//綁定ID為txt2的txtInput
//綁定屬性為txtInput的text
//監視者ID為txt1的txtInput
//監視者屬性為txtInput的text
watcher1 = BindingUtils.bindProperty(txt2,"text",txt1,"text");

//綁定ID為txtComb的txtInput
//綁定屬性為txtInput的text
//監視者ID為comb的ComboBox
//監視者屬性為ComboBox的value
watcher2 = BindingUtils.bindProperty(txtComb,"text",comb,"value");
}

/**
* 解除綁定
* @return void
* **/
private function UnBinding():void {
//解除綁定
watcher1.unwatch();
watcher2.unwatch();
}
]]-->
</mx:Script>

<mx:ApplicationControlBar dock="true">
<mx:Button label="動態綁定" click="Binding();"/>
<mx:Button label="解除綁定" click="UnBinding();"/>
</mx:ApplicationControlBar>

<mx:VBox width="200" height="200">

<mx:Spacer height="30"/>

<mx:TextInput id="txt1"/>
<mx:TextInput id="txt2"/>

<mx:Spacer height="30"/>

<mx:ComboBox id="comb">
<mx:dataProvider>
<mx:Array>
<mx:String>Beijing</mx:String>
<mx:String>Shanghai</mx:String>
<mx:String>Hangzhou</mx:String>
</mx:Array>
</mx:dataProvider>
</mx:ComboBox>

<mx:TextInput id="txtComb"/>
</mx:VBox>
</mx:Application>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.