您的位置:首页 > 其它

Flex-数据绑定

2012-03-26 19:55 260 查看
Flex绑定,有三种方式。

1、直接通过{}实现绑定;

eg:
<s:TextInput id="txtFirst"/>
<s:TextInput id="txtSecond" text="{txtFirst.text}"/>//实现第二个输入框值与第一个同步


2、简单的绑定方式。

在<fx:Script>代码中,通过"[Bindable]"关键字实现绑定

3、使用<fx:Binding source="绑定源" destination="目标" />实现绑定

*使用<fx:Binding 中可以通过 twoWay 属性实现双向绑定 twoWay="true"

绑定的代码:

<?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="400" minHeight="300">
<s:layout>
<s:VerticalLayout verticalAlign="middle" horizontalAlign="center" />
</s:layout>
<fx:Declarations>

</fx:Declarations>
<fx:Binding source="txtFirst.text" destination="labFirst.text" />

<fx:Script>
<![CDATA[
[Bindable]
private var str:String;
private function drogSlider():void{
str = String(sliderFirst.value);
}
]]>
</fx:Script>

<s:Label id="labFirst" text="初始值"/>
<s:TextInput id="txtFirst"/>
<s:TextInput id="txtSecond" text="{txtFirst.text}"/>
<s:HSlider id="sliderFirst" change="drogSlider();"/>
<s:Label id="labSecond" text="划条值是:{str}"/>
</s:Application>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: