将 Spark RadioButtonGroup 数据绑定到 Spark RadioButton 值
我有两个单选按钮,我试图将其绑定到 dataProvider 的值。它最初填充该值,但如果我在代码中更改 dp 它不会执行任何操作。我错过了什么吗?
这是一个工作示例
<?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"
>
<fx:Declarations>
<s:RadioButtonGroup id="oneGroup" selectedValue="{dataProvider.one}"/>
<s:RadioButtonGroup id="twoGroup" selectedValue="{dataProvider.two}"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var dataProvider:Object = {one:"active",two:false};
public function doinit(e:Event):void {
dataProvider.one = dataProvider.one == "inactive" ? "active":"inactive";
dataProvider.two = !dataProvider.two;
result.text = dataProvider.one + ":" + dataProvider.two;
}
]]>
</fx:Script>
<mx:HBox>
<mx:Form>
<mx:FormItem label="One" direction="horizontal" >
<s:RadioButton groupName="oneGroup" value="active" label="Active" />
<s:RadioButton groupName="oneGroup" value="inactive" label="Inactive" />
</mx:FormItem>
<mx:FormItem label="Two" direction="horizontal" >
<s:RadioButton groupName="twoGroup" value="true" label="True" />
<s:RadioButton groupName="twoGroup" value="false" label="False" />
</mx:FormItem>
<s:Button label="Change DP" click="doinit(event)" />
<s:Label id="result" />
</mx:Form>
</mx:HBox>
</s:Application>
I have two radio buttons I am trying to bind to the value of a dataProvider. It populates the value initially, but if I change dp in my code it doesn't do anything. Am I missing something?
Here is a working example
<?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"
>
<fx:Declarations>
<s:RadioButtonGroup id="oneGroup" selectedValue="{dataProvider.one}"/>
<s:RadioButtonGroup id="twoGroup" selectedValue="{dataProvider.two}"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var dataProvider:Object = {one:"active",two:false};
public function doinit(e:Event):void {
dataProvider.one = dataProvider.one == "inactive" ? "active":"inactive";
dataProvider.two = !dataProvider.two;
result.text = dataProvider.one + ":" + dataProvider.two;
}
]]>
</fx:Script>
<mx:HBox>
<mx:Form>
<mx:FormItem label="One" direction="horizontal" >
<s:RadioButton groupName="oneGroup" value="active" label="Active" />
<s:RadioButton groupName="oneGroup" value="inactive" label="Inactive" />
</mx:FormItem>
<mx:FormItem label="Two" direction="horizontal" >
<s:RadioButton groupName="twoGroup" value="true" label="True" />
<s:RadioButton groupName="twoGroup" value="false" label="False" />
</mx:FormItem>
<s:Button label="Change DP" click="doinit(event)" />
<s:Label id="result" />
</mx:Form>
</mx:HBox>
</s:Application>
Link to documentation...
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/controls/RadioButtonGroup.html#selectedValue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用以下类来利用数据绑定:
因此对于您的示例:
Try to use the following class to have advantage of data binding:
So for your sample:
fwiw,这里是使标准对象可绑定的代码。忽略我对上面 s:Label 的评论,不知道为什么这对我不起作用。
fwiw, here is the code to make a standard object bindable. Ignore my comment on s:Label above, not sure why that wasn't working for me.