在 Flex 中,如何取消选择组中的所有单选按钮?

发布于 2024-07-26 09:43:48 字数 168 浏览 5 评论 0原文

在 Flex 中,有时当您需要清除表单时,您会遇到单选按钮组似乎无法清除的问题:尽您所能,在所有按钮上设置 selected=false,在组上设置 Selection=null,同时执行这两个操作,执行两次等等,你似乎总是会得到一个仍然被选中的讨厌的小单选按钮。 如何解决这个问题并将单选按钮组恢复到初始的无选择状态?

In Flex, sometimes when you need to clear a form you run into the problem that radio button groups seem to defy clearing: try as you might, setting selected=false on all buttons, setting selection=null on the group, doing both, doing them twice, etc., you always seem to end up with one pesky little radio button that's still selected. How do you solve this and restore the radio button group to its initial no-selection state?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(7

抽个烟儿 2024-08-02 09:43:48

您需要将所有单选按钮分组到 RadioButtonGroup 然后将组选择设置为空:

<mx:RadioButtonGroup id="myGroup" />

<mx:RadioButton label="One" groupName="myGroup" />
<mx:RadioButton label="Two" groupName="myGroup" />
<mx:RadioButton label="Three" groupName="myGroup" />

<mx:Button label="Clear" click="myGroup.selection = null;" />

You need to group all of the radio buttons into a RadioButtonGroup and then set the group selection to null:

<mx:RadioButtonGroup id="myGroup" />

<mx:RadioButton label="One" groupName="myGroup" />
<mx:RadioButton label="Two" groupName="myGroup" />
<mx:RadioButton label="Three" groupName="myGroup" />

<mx:Button label="Clear" click="myGroup.selection = null;" />
合约呢 2024-08-02 09:43:48

您可以尝试将所有单选按钮设置为 RadioButtonGroup,然后将 RadioButtonGroup.selection 设置为 null

请参阅http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html#includeExamplesSummary 有关如何实现的参考RadioButtonGroup 控件。

You could try setting all of your radio buttons to a RadioButtonGroup then set RadioButtonGroup.selection to null

See http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html#includeExamplesSummary for reference on how to implement the RadioButtonGroup control.

紧拥背影 2024-08-02 09:43:48

据我所知,解决此问题的唯一方法是添加一个隐藏的虚拟单选按钮,您可以选择该单选按钮以取消选择所有其他按钮。

The only way to solve this that I know of is to add a hidden dummy radio button that you select in order to deselect all the others.

戈亓 2024-08-02 09:43:48

这不行吗?

      function clearRadioSelection(theGroup) {
        theGroup.selection.selected = false;
        theGroup.selectedRadio = undefined;
        theGroup.dispatchEvent({type:"change"});
  }

theGroup 是单选按钮组(不是单个单选按钮)
来自:http://kb2.adobe.com/cps/000/c4e4be2f.html< /a>

Does this not work?

      function clearRadioSelection(theGroup) {
        theGroup.selection.selected = false;
        theGroup.selectedRadio = undefined;
        theGroup.dispatchEvent({type:"change"});
  }

theGroup is the radio button group (not the individual radio buttons)
from: http://kb2.adobe.com/cps/000/c4e4be2f.html

一城柳絮吹成雪 2024-08-02 09:43:48

我相信您正在使用 RadiobuttonGroup 并绑定特定组的所有单选按钮控件。

所以,简单的方法:

private function radioGroupReset():void

{

radioGroup1.selection = null;

应该可行!

I believe you are using the RadiobuttonGroup and binding all the radiobutton controls for the perticular group.

So, easy way:

private function radioGroupReset():void

{

radioGroup1.selection = null;

}

This should work!

看轻我的陪伴 2024-08-02 09:43:48

显然,前面的答案应该以最干净的方式让您到达目的地,但是如果您将头撞到墙上,只需将所有单选按钮收集到一个组件中,然后在需要清除它时重新绘制整个组件。 问题解决了。

无论如何,表格充其量只是笨拙的。 没必要让生活太艰难。

Obviously the previous answers should get you where you're going in the cleanest way, but if you're hitting your head against the wall, just collect all your radio buttons into a component and then redraw the entire component when you need to clear it. Problem solved.

Forms are gimpy at best anyway. No need to make life too hard.

独自←快乐 2024-08-02 09:43:48

只需将 radioButtonGroup 的选择属性设置为 null,它就会进入其初始状态。

例如,如果

               <mx:RadioButtonGroup id="answers" />

在 ActionScript 中编写以下行,

                answers.selection = null;

则会重置该组,并且不会选择任何单选按钮。 希望对您有帮助。 我从以下链接中得到了这个想法。 祝你好运。

http://blog.flexexamples .com/2008/01/06/clearing-a-selected-radiobutton-control-in-flex/

Simply set the selection property of the radioButtonGroup to null and the it'll go to its initial condition.

e.g, if

               <mx:RadioButtonGroup id="answers" />

then writing the following line in ActionScript

                answers.selection = null;

would reset the group with no radio button selected left. Hope it helps you. I took the idea from following link. Best of luck.

http://blog.flexexamples.com/2008/01/06/clearing-a-selected-radiobutton-control-in-flex/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文