当前位置:   article > 正文

使用RadioButtonGroup 取值和赋值的例子

使用RadioButtonGroup 取值和赋值的例子
 

组中所选 RadioButton 组件的 value 属性, 如果没有设置 则为所选 RadioButton 组件的 label 属性。如果未选择任何 RadioButton,则此属性为 null

如果设置了 selectedValue,则 Flex 会选择 valuelabel 属性与此值匹配的第一个 RadioButton 组件。

此属性可用作数据绑定的源代码。

 

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"   
  3.                xmlns:s="library://ns.adobe.com/flex/spark"   
  4.                xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">  
  5.     <s:layout>  
  6.         <s:BasicLayout/>  
  7.     </s:layout>  
  8.     <fx:Script>  
  9.         <![CDATA[  
  10.             import spark.events.IndexChangeEvent;  
  11.   
  12.             protected function dropdownlist1_changeHandler(event:IndexChangeEvent):void  
  13.             {  
  14.                 this.Color.selectedValue = event.target.selectedItem.toString();  
  15.             }  
  16.   
  17.         ]]>  
  18.     </fx:Script>  
  19.     <fx:Declarations>  
  20.         <s:RadioButtonGroup id="Color" enabled="{checkBox.selected}" />  
  21.     </fx:Declarations>  
  22.       
  23.     <s:RadioButton x="76" y="36" label="红色" value="red"  groupName="Color"/>  
  24.     <s:RadioButton x="76" y="62" label="蓝色" value="blue" groupName="Color"/>  
  25.     <s:RadioButton x="76" y="144" label="黄色" value="yellow" groupName="Color"/>  
  26.     <s:RadioButton x="76" y="118" label="绿色" value="green" groupName="Color"/>  
  27.     <s:RadioButton x="76" y="92" label="紫色" value="purple" groupName="Color"/>  
  28.     <s:Label x="44" y="184" text="{this.Color.selectedValue}" width="519" height="57" color="#FF0000" fontWeight="bold" fontSize="35"/>  
  29.     <s:CheckBox x="44" y="10" label="是否有效" id="checkBox" selected="true"/>  
  30.     <s:DropDownList x="44" y="240" change="dropdownlist1_changeHandler(event)">  
  31.         <s:dataProvider>  
  32.             <s:ArrayList source="[red,blue,yellow,green,purple]"></s:ArrayList>  
  33.         </s:dataProvider>  
  34.     </s:DropDownList>  
  35. </s:Application>  

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

Java代码
  1. <?xml version="1.0" encoding="utf-8"?>   
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">   
  3.     <mx:Script>   
  4.         <![CDATA[   
  5.             private var o1:Object={a:1,b:2};   
  6.             private var o2:Object={a:2,b:2};   
  7.         ]]>   
  8.     </mx:Script>   
  9.     <mx:HBox>   
  10.        
  11.     <mx:RadioButtonGroup id="sexes"/>   
  12.     <mx:RadioButton id="r1" groupName="sexes" label="男" value="{o1}"/>   
  13.     <mx:RadioButton groupName="sexes" label="女" value="{o2}"/>   
  14.     <mx:Button click="trace(r1.value.a);sexes.selectedValue=o1;"/>       
  15.     </mx:HBox>   
  16. </mx:Application>  
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3. <mx:Script>
  4. <![CDATA[
  5. private var o1:Object={a:1,b:2};
  6. private var o2:Object={a:2,b:2};
  7. ]]>
  8. </mx:Script>
  9. <mx:HBox>
  10. <mx:RadioButtonGroup id="sexes"/>
  11. <mx:RadioButton id="r1" groupName="sexes" label="男" value="{o1}"/>
  12. <mx:RadioButton groupName="sexes" label="女" value="{o2}"/>
  13. <mx:Button click="trace(r1.value.a);sexes.selectedValue=o1;"/>
  14. </mx:HBox>
  15. </mx:Application>

 value属性可以指向一个对象,但其值必须是一个对象的引用,即如果把{a:1,b:2}直接赋给r1.value,再执行sexes.selectedValue={a:1,b:2},则r1不会被选中。

 

http://www.cnblogs.com/xxcainiao/articles/1236219.html
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/613495
推荐阅读
相关标签
  

闽ICP备14008679号