单个数组元素做为数据绑定源时

Flex 数据绑定详解
[size=large]绑定到数组中的元素[/size]

可以使用数组中的单个元素作为数据绑定源,如下例所示:
<?xml version="1.0"?>
<!-- binding/ArrayBinding.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var myAC:ArrayCollection = new ArrayCollection([
"One", "Two", "Three", "Four"]);
[Bindable]
public var myAC2:ArrayCollection = new ArrayCollection([
"Uno", "Dos", "Tres", "Quatro"]);
]]>
</mx:Script>
<!-- Data binding updated at application startup
and when myAC modified. -->
<mx:Text id="text1" text="{myAC[0]}"/>
<!-- Data binding updated at application startup,
when myAC modified, and when myAC[0] modified. -->
<mx:Text id="text2" text="{myAC.getItemAt(0)}"/>
<mx:Button id="button1"
label="Change Element"
click="myAC[0]='new One'"/>
<mx:Button id="button2"
label="Change ArrayCollection"
click="myAC=myAC2"/>
</mx:Application>
[color=darkred]如果通过方括号语法[]来指定数组元素作为数据绑定表达式的源,那么数据绑定只在应用
启动时触发,或者在数组或其引用被更新时触发。当这个数组元素被更新的时候不会触发数据
绑定。
但数据绑定表达式中的myAC.getItemAt(0)则会在该数组元素变化时被触发更新。[/color]因此,id
为 text2 的Text 控件在点击button1 时会被更新,而id 为text1 的Text 控件则不会被更新。
当使用数组中的元素作为数据绑定表示的源时,应当在绑定表达式中使用
ArrayCollection.getItemAt()方法。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值