将 Spark RadioButtonGroup 数据绑定到 Spark RadioButton 值

发布于 2024-11-24 21:49:34 字数 2157 浏览 2 评论 0原文

我有两个单选按钮,我试图将其绑定到 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>

链接到文档... http://help.adobe.com /en_US/FlashPlatform/reference/actionscript/3/mx/controls/RadioButtonGroup.html#selectedValue

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯到世界奔溃 2024-12-01 21:49:34

尝试使用以下类来利用数据绑定:

package
{

[Bindable]
public class DP
{
    public var one:String;
    public var two:Boolean;

    public function DP(one:String, two:Boolean)
    {
        this.one = one;
        this.two = two;
    }
}
}

因此对于您的示例:

<?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[
        [Bindable] 
        public var dataProvider:DP = new DP("active", false);

        public function doinit(e:Event):void {
            dataProvider.one = "inactive";
            dataProvider.two = true;
        }
    ]]>
    </fx:Script>
    <mx:HBox>
        <mx:Form>
            <mx:FormItem label="One" direction="horizontal" >
                <s:RadioButton group="{oneGroup}" value="active" label="Active" />
                <s:RadioButton group="{oneGroup}" value="inactive" label="Inactive" />
            </mx:FormItem>
            <mx:FormItem label="Two" direction="horizontal" >
                <s:RadioButton group="{twoGroup}" value="true" label="True" />
                <s:RadioButton group="{twoGroup}" value="false" label="False" />
            </mx:FormItem>
            <s:Button label="Change DP" click="doinit(event)" />
        </mx:Form>
    </mx:HBox>
</s:Application>

Try to use the following class to have advantage of data binding:

package
{

[Bindable]
public class DP
{
    public var one:String;
    public var two:Boolean;

    public function DP(one:String, two:Boolean)
    {
        this.one = one;
        this.two = two;
    }
}
}

So for your sample:

<?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[
        [Bindable] 
        public var dataProvider:DP = new DP("active", false);

        public function doinit(e:Event):void {
            dataProvider.one = "inactive";
            dataProvider.two = true;
        }
    ]]>
    </fx:Script>
    <mx:HBox>
        <mx:Form>
            <mx:FormItem label="One" direction="horizontal" >
                <s:RadioButton group="{oneGroup}" value="active" label="Active" />
                <s:RadioButton group="{oneGroup}" value="inactive" label="Inactive" />
            </mx:FormItem>
            <mx:FormItem label="Two" direction="horizontal" >
                <s:RadioButton group="{twoGroup}" value="true" label="True" />
                <s:RadioButton group="{twoGroup}" value="false" label="False" />
            </mx:FormItem>
            <s:Button label="Change DP" click="doinit(event)" />
        </mx:Form>
    </mx:HBox>
</s:Application>
蓝咒 2024-12-01 21:49:34

fwiw,这里是使标准对象可绑定的代码。忽略我对上面 s:Label 的评论,不知道为什么这对我不起作用。

<?xml version="1.0" encoding="utf-8"?>
<mx: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:Script>
    <![CDATA[

        [Bindable(event="OneChanged")] 
        public var dataProvider:Object = {one:"one"};

        private function changeOne():void{

            switch(dataProvider.one){
                case "one":
                    // property
                    dataProvider.one="two"; 
                    break;
                case "two":
                    // whole value
                    dataProvider = {one : "one"};
                    break;
            }
            dispatchEvent (new Event ("OneChanged"));
        }
    ]]>
    </fx:Script>
    <s:VGroup>
        <s:Label text="{dataProvider.one}" />
        <s:Button click="changeOne()" label="Next" />
    </s:VGroup> 
</mx:Application>

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.

<?xml version="1.0" encoding="utf-8"?>
<mx: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:Script>
    <![CDATA[

        [Bindable(event="OneChanged")] 
        public var dataProvider:Object = {one:"one"};

        private function changeOne():void{

            switch(dataProvider.one){
                case "one":
                    // property
                    dataProvider.one="two"; 
                    break;
                case "two":
                    // whole value
                    dataProvider = {one : "one"};
                    break;
            }
            dispatchEvent (new Event ("OneChanged"));
        }
    ]]>
    </fx:Script>
    <s:VGroup>
        <s:Label text="{dataProvider.one}" />
        <s:Button click="changeOne()" label="Next" />
    </s:VGroup> 
</mx:Application>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文