• Flex控件之repeater和radioButton应用


    代码:http://www.cnblogs.com/modou/articles/2108346.html

    <?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="955" minHeight="600">
        <s:layout> 
            <s:BasicLayout/> 
        </s:layout> 
        
        <fx:Script> 
            <![CDATA[ 
                import mx.controls.Alert; 
                import mx.events.FlexEvent; 
                
                protected function button1_clickHandler(event:MouseEvent):void
                { 
                    Alert.show(radiogroup1.selectedValue.toString()); 
                } 
                
                
                protected function radiobutton1_creationCompleteHandler(event:FlexEvent):void
                { 
                    
                    var rb:RadioButton =event.currentTarget as RadioButton; 
                    if(rb==radiogroup1.getRadioButtonAt(2)) 
                    { 
                        rb.selected = true; 
                    } 
                } 
                
            ]]> 
        </fx:Script> 
        
        
        <fx:Declarations> 
            
            <fx:Array id="arr"> 
                <fx:Object label="北京" data="010" /> 
                <fx:Object label="上海" data="021" /> 
                <fx:Object label="天津" data="022" /> 
                <fx:Object label="重庆" data="023" /> 
                <fx:Object label="广州" data="020" /> 
            </fx:Array> 
            
            <s:RadioButtonGroup id="radiogroup1"  /> 
        </fx:Declarations> 
        
        <s:Button x="336" y="316" label="按钮" click="button1_clickHandler(event)"/> 
        <mx:VBox x="100" y="200" height="200" width="200" borderVisible="true" borderStyle="outset"> 
            <mx:Repeater dataProvider="{arr}"  id="radioRepeater" x="52" y="38"> 
                <s:RadioButton label="{radioRepeater.currentItem.label}" value="{radioRepeater.currentItem.data}" groupName="radiogroup1"
    creationComplete="radiobutton1_creationCompleteHandler(event)" /> </mx:Repeater> </mx:VBox> </s:Application>

    1.首先先用fx:Array生成数据对象,fx:Array需要放在fx:Declarations声明部分

    2.添加一个s:RadioButtonGroup,也需要放在fx:Declarations声明部分

    3.添加一个mx:Repeater组件,并在mx:Repeater组件内添加一个s:RadioButton组件给mx:Repeater组件设置数据源,那么数据源有几条数据,就会生成几个RadioButton

      由于mx:Repeater组件必须包在基于Halo的容器中,所以还需要在mx:Repeater组件外包一个mx:VBox组件

    4.通过radiogroup1.selectedValue.toString(),可以获取当前选择项的value值

    5.如果需要默认绑定第一个RadioButton,可以在RadioButton组件添加creationComplete事件,监测如果是第一项,就选中

  • 相关阅读:
    ORACLE的专用模式和共享模式(转)
    用TSQL修改数据库的恢复模型
    Python中的数组
    hotmail是如何被劫持的?
    [收藏] vss自动备份
    在Oracle中模拟ms Sql 中的自动增加字段
    Oracle重建所有表和索引
    CentOS6.0安装PostgreSQL9.1
    linux查找文件命令find
    Linux修改网络配置
  • 原文地址:https://www.cnblogs.com/lbangel/p/3203691.html
Copyright © 2020-2023  润新知