加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex-数据绑定

发布时间:2020-12-15 05:09:48 所属栏目:百科 来源:网络整理
导读:Flex绑定,有三种方式。 1、直接通过{}实现绑定; eg: s:TextInput id="txtFirst"/s:TextInput id="txtSecond" text="{txtFirst.text}"///实现第二个输入框值与第一个同步 2、简单的绑定方式。 在fx:Script代码中,通过"[Bindable]"关键字实现绑定 3、使用fx:


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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读