using_data_binding

Binding expressions in curly braces can contain an ActionScript expression that returns a value. For example, you can use the curly braces syntax for the following types of binding:

  • A single bindable property inside curly braces
  • String concatenation that includes a bindable property inside curly braces
  • Calculations on a bindable property inside curly braces
  • Conditional operations that evaluate a bindable property value
<?xml version="1.0" encoding="utf-8"?>
<mx:Application 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    viewSourceURL="src/DataBindingActionScriptExpressionsSimple/index.html"    
    width="420" height="350"
 >
    <mx:Model id="myModel">

        <myModel>
            <!-- Perform simple property binding. -->
            <a>{nameInput.text}</a>
            <!-- Perform string concatenation. -->
            <b>This is {nameInput.text}</b>

            <!-- Perform a calculation. -->
            <c>{(Number(numberInput.text) as Number) * 6 / 7}</c>

            <!-- Perform a conditional operation using a ternary operator;
                the person object contains a Boolean variable called isMale. -->
            <d>{(isMale.selected) ? "Mr." : "Ms."} {nameInput.text}</d> 
        </myModel>

    </mx:Model>

    <mx:Panel 
        paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10"

        width="100%" height="100%"
        title="Binding expressions"
    >
        <mx:Form>
            <mx:FormItem label="Last Name:">

                <mx:TextInput id="nameInput"/>
            </mx:FormItem>            
            <mx:FormItem label="Select sex:">
                <mx:RadioButton 
                    id="isMale" 
                    label="Male" 
                    groupName="gender"

                    selected="true"
                />
                <mx:RadioButton 
                    id="isFemale" 
                    label="Female" 
                    groupName="gender"

                />
            </mx:FormItem>
            <mx:FormItem label="Enter a number:">
            <mx:TextInput id="numberInput" text="0"/>

            </mx:FormItem>            
        </mx:Form>
        
        <mx:Text text="{'Simple binding: '+myModel.a}"/>
        <mx:Text text="{'String concatenation: '+myModel.b}"/>

        <mx:Text text="{'Calculation: '+numberInput.text+' * 6 / 7 = '+myModel.c}"/>        
        <mx:Text text="{'Conditional: '+myModel.d}"/>

    </mx:Panel>    
</mx:Application>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值