Flex 数据绑定
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 "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 数据绑定的更多相关文章
- Flex数据绑定陷阱(一)
Flex数据绑定陷阱:常见的误用和错误 当构建Flex或者Adobe AIR程序时,将一个对象的值自动的传递给另一个对象这种处理是数据绑定最常 用并最有用的特征之一. 尽管如此,同时数据绑定会减缓程序 ...
- 天津政府应急系统之GIS一张图(arcgis api for flex)讲解(十三)台风模块
config.xml文件的配置如下: <widget label="台风" icon="assets/images/typhoon.png" config ...
- 转 Flex MXML编译成AS类
2009-09-22 23:25 Flex MXML编译成AS类 由“Flex 基础”文中可知:每一个mxml文件首先要编译成as文件,然后再译成swf文件.app.mxml文件编译后会产生一系列中间 ...
- Flex Builder读书笔记(二)——MXML
MXML类似于HTML,它提供各种标签来定义用户界面,但是它比HTML的结构更为严格,并拥有跟多的应用标签.MXML不仅包括可视标签,还包括不可视标签,如web service连接.数据绑定和动画效果 ...
- Silverlight项目笔记1:UI控件与布局、MVVM、数据绑定、await/async、Linq查询、WCF RIA Services、序列化、委托与事件
最近从技术支持转到开发岗,做Silverlight部分的开发,用的Prism+MVVM,框架由同事搭好,目前做的主要是功能实现,用到了一些东西,侧重于如何使用,总结如下 1.UI控件与布局 常用的主要 ...
- Flex学习总结
Flex SDK Flex框架类库.Flex编译环境.调式器.MXML.ActionScript编程语言以及其它工具组成,Flash Builder是其开发环境, Flash Player的工作模 ...
- Flex Metadata tags 元数据标签
1.[Alternative] [可替换] 标明此类可以被参数中的类替换,版本号说明发生替换的版本. [Alternative]和[Deprecated] 不同.如果是[不建议使用]的类,以后的版本可 ...
- Flex中的折线图
1.问题背景 在Flex中,制作一个折线图.而且给折线图的横轴和纵轴进行样式设置,详细实现过程例如以下: 2.实现实例 (1)设置横轴样式和数据绑定 <mx:horizontalAxis> ...
- Flex 事件机制
使用ActionScript的单击事件示例 <?xml version="1.0" encoding="utf-8"?> <s:Applica ...
随机推荐
- HDU 1114 Piggy-Bank(判断是否恰好装满的背包)
其实这道题在寒假自学训练赛的时候就做过,不过感觉现在的理解跟当时真的不一样,大一半年过去了,变了这么多,我们都在进步,一回头便走出了这么远... 好了,题目很简单,一个背包,装不满做一个标记就行了 # ...
- jTDS Java连接SQL Server 2000数据库
Java连接SQL Server 2000数据库时,有两种方法: (1)通过Microsoft的JDBC驱动连接.此JDBC驱动共有三个文件,分别 是mssqlserver.jar.msutil.ja ...
- Web爬去的C#请求发送
public class HttpControler { //post请求发送 private Encoding m_Encoding = Encoding.GetEncoding("gb2 ...
- tls session resumption
http://stackoverflow.com/questions/12318325/resume-tls-connection-in-java As long as you use the sam ...
- html5绘图
html5绘图 这是我在绘图过程中遇到的问题,求助高手帮忙啊... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 ...
- 最简单的ajax调用webservice
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestHelloWorld ...
- PHP 安装 redis、memcached、openssl、pdo_mysql等
PHP openssl 扩展的安装 这些插件可以通过在 php.ini 中添加 extension 的方式来加载所需要的插件,其实在 php 的安装包里就已经有相关的插件代码包了,在 php7 ...
- 解决phpcms V9缩略图模糊的方法
解决V9缩略图模糊/libs/classes/image.class.php注释掉else imagecopyresized($thumbimg, $srcimg, 0, 0, $psrc_x, ...
- android MessageQueue入门
接触安卓几年了.但是感觉一直不是很明白,东西太多了.反过来说就是自己太菜了.很多东西其实都是模凌两可,不熟悉,很多知识点都是知道一点,最多大家都这样用.没问题,事件长了也一直这样用的.但是有个问题,安 ...
- MIPI-3
上一篇文章讲了以下D_PHY层,这只是最底层的,针对于显示,上层由分出了四种,由专门的工作组进行定义,显示器方面叫做display wrok group,主要分为 DSC(display comman ...