Flex 数据绑定

<?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"
height="662">
<fx:Script>
<![CDATA[
import mx.binding.utils.BindingUtils;
import mx.binding.utils.ChangeWatcher;
[Bindable]
private var str:String = "asdf";
private var watcher1:ChangeWatcher;
private var watcher2:ChangeWatcher;
protected function button1_clickHandler(event:MouseEvent):void{
str += 'a';
}
protected function btnBind01_clickHandler(event:MouseEvent):void{
// bindProperty(目标对象,目标对象属性,源对象,源对象属性)
watcher1 = BindingUtils.bindProperty(txt004,'text',txt005,'text');
} protected function btnUnbind01_clickHandler(event:MouseEvent):void{
watcher1.unwatch();
} protected function btn004_clickHandler(event:MouseEvent):void{
watcher2 = BindingUtils.bindProperty(txt010,'text',txt011,'text');
// 不一定非要赋值给watcher
BindingUtils.bindProperty(txt011,'text',txt010,'text');
} ]]>
</fx:Script>
<fx:Declarations>
<fx:Model id="person">
<info>
<name>
<first>John</first>
<last>Doe</last>
<full>{person.name.first}.{person.name.last}</full>
</name>
<email>a@b.c</email>
<phone>1234567</phone>
</info>
</fx:Model>
</fx:Declarations>
<!-- fx:Binding必须为根的子元素 -->
<fx:Binding destination="txt003.text" source="txt002.text"/>
<fx:Binding destination="txt009.text" source="txt008.text" twoWay="true"/>
<s:TextInput id="txt001" x="212" y="50"/>
<s:TextInput x="212" y="100" enabled="false" text="绑定:{txt001.text}"/>
<s:TextInput x="212" y="150" text="绑定到对象不好:{txt001}"/><!-- 这样绑定只会绑定其id -->
<s:TextInput x="212" y="200" text="{str}"/>
<s:Button x="352" y="201" label="绑定到变量中" click="button1_clickHandler(event)"/>
<s:Label x="212" y="245" width="151" height="23" text="串联:{txt001.text} {txt001.text}'s &quot;ABC"/>
<s:TextInput id="txt002" x="471" y="50" text="使用fx:Bingding进行绑定"/>
<s:TextInput id="txt003" x="471" y="100"/>
<s:Panel x="476" y="130" width="250" height="200" title="使用BindingUtils类创建绑定">
<s:TextInput id="txt004" x="21" y="10" text="目标"/>
<s:TextInput id="txt005" x="21" y="40" text="源"/>
<s:Button id="btnBind01" x="21" y="87" label="绑定" click="btnBind01_clickHandler(event)"/>
<s:Button id="btnUnbind01" x="113" y="87" label="解除" click="btnUnbind01_clickHandler(event)"/>
</s:Panel>
<s:Panel x="194" y="290" width="250" height="299" title="双向数据绑定三种方式">
<s:TextInput id="txt006" x="10" y="19"/>
<s:TextInput id="txt007" x="10" y="58" text="@{txt006.text}"/>
<s:TextInput id="txt008" x="10" y="98"/>
<s:TextInput id="txt009" x="10" y="132"/>
<mx:HRule x="10" y="88" width="172"/>
<mx:HRule x="10" y="162" width="172" height="1"/>
<s:TextInput id="txt010" x="10" y="171"/>
<s:TextInput id="txt011" x="10" y="201"/>
<s:Button id="btn004" x="146" y="202" label="双向绑定" click="btn004_clickHandler(event)"/>
<s:Label x="158" y="29" text="表达式方式"/>
<s:Label x="158" y="108" text="fx:Binding"/>
<s:Label x="158" y="182" text="BindingUtis"/>
</s:Panel>
<s:Panel x="476" y="389" width="250" height="200" title="数据模型和多级绑定">
<s:TextInput x="10" y="27" text="@{person.name.first}"/>
<s:Label x="10" y="92" text="{person.name.full}"/>
</s:Panel>
</s:Application>

Flex 数据绑定的更多相关文章

  1. Flex数据绑定陷阱(一)

    Flex数据绑定陷阱:常见的误用和错误 当构建Flex或者Adobe AIR程序时,将一个对象的值自动的传递给另一个对象这种处理是数据绑定最常 用并最有用的特征之一. 尽管如此,同时数据绑定会减缓程序 ...

  2. 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十三)台风模块

    config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config ...

  3. 转 Flex MXML编译成AS类

    2009-09-22 23:25 Flex MXML编译成AS类 由“Flex 基础”文中可知:每一个mxml文件首先要编译成as文件,然后再译成swf文件.app.mxml文件编译后会产生一系列中间 ...

  4. Flex Builder读书笔记(二)——MXML

    MXML类似于HTML,它提供各种标签来定义用户界面,但是它比HTML的结构更为严格,并拥有跟多的应用标签.MXML不仅包括可视标签,还包括不可视标签,如web service连接.数据绑定和动画效果 ...

  5. Silverlight项目笔记1:UI控件与布局、MVVM、数据绑定、await/async、Linq查询、WCF RIA Services、序列化、委托与事件

    最近从技术支持转到开发岗,做Silverlight部分的开发,用的Prism+MVVM,框架由同事搭好,目前做的主要是功能实现,用到了一些东西,侧重于如何使用,总结如下 1.UI控件与布局 常用的主要 ...

  6. Flex学习总结

    Flex SDK Flex框架类库.Flex编译环境.调式器.MXML.ActionScript编程语言以及其它工具组成,Flash Builder是其开发环境,   Flash Player的工作模 ...

  7. Flex Metadata tags 元数据标签

    1.[Alternative] [可替换] 标明此类可以被参数中的类替换,版本号说明发生替换的版本. [Alternative]和[Deprecated] 不同.如果是[不建议使用]的类,以后的版本可 ...

  8. Flex中的折线图

    1.问题背景 在Flex中,制作一个折线图.而且给折线图的横轴和纵轴进行样式设置,详细实现过程例如以下: 2.实现实例 (1)设置横轴样式和数据绑定 <mx:horizontalAxis> ...

  9. Flex 事件机制

    使用ActionScript的单击事件示例 <?xml version="1.0" encoding="utf-8"?> <s:Applica ...

随机推荐

  1. Android复习--广播

    广播有两种方式,一种静态广播,一种动态广播. 静态广播-->静态广播接收器在配置文件里面注册. 动态广播-->而动态广播接收器在代码里面注册. 广播的发送: Context.sendBro ...

  2. D. Bear and Two Paths(贪心构造)

    D. Bear and Two Paths time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  3. [iOS]C语言技术视频-09-枚举的定义

    下载地址: 链接: http://pan.baidu.com/s/1o625Ee2 密码: 8kp5

  4. MariaDB GTID 复制同步

    MariaDB GTID 复制同步 GTID:Global Transaction ID,全局事务ID,在整个主从复制架构中任何两个事物ID是不能相同的.全局事务ID是Mster服务器生成一个128位 ...

  5. MAC OS X 10.10 应用程序下载失败后lunchpad产生灰色图标的解决办法

    方法如下:打开应用程序- 实用工具 - 终端. 以此出入如下字符 defaults write com.apple.dock ResetLaunchPad -bool true killall Doc ...

  6. JS表单原生验证器

    一.前言 最近在开发一个新项目,需要做登陆等一系列的表单提交页面.在经过“缜密”的讨论后,我们决定 不用外部流行的框架,如bootstrap,由于我负责的模块 仅仅是其中的一部分,因此少数服从多数,无 ...

  7. Octave使用感想

    Octave是一门比较 简单.原始 的语言.从某方面来说和 shell 语言类似,只不过,shell语言主要用于 操作系统管理方面,而Octave侧重于科学计算方面. 语言本身没有提供或者说很简单的 ...

  8. php中使用mysql_fetch_object向页面输出结果,总结!

    public function selectResultByThird() { if ((!empty ($_REQUEST["bigname"])) && (!e ...

  9. 远离DoS攻击 Windows Server 2016发布DNS政策

             Windows Server 2016的网络功能虽然没有获得像Docker容器和Nano Server同等重要的关注,但是管理员们应该了解的是,新的域名系统(Domain Name ...

  10. margin负值-内秀篇

    zccst整理 margin系列之布局篇 margin系列之bug巡演(三) margin系列之bug巡演(二) margin系列之内秀篇(二) margin系列之bug巡演 margin系列之内秀篇 ...