如何:AS3 中自定义 DataGridColumn ItemRenderer 中的 RadioButton
我有一个数据网格,我想使用 AS3 (而不是 mxml)添加一列单选按钮。我可以使用自定义 itemRenderer 来做到这一点。
var dgc:DataGridColumn = new DataGridColumn();
dgc.itemRenderer = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);
在我的 RadioBtnColumnItemRenderer.mxml 中,我有一个带有 radioButton 的框...如下所示:
<?xml version="1.0" encoding="utf-8"?>
<mx:Box
xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center" verticalAlign="middle"
>
<mx:RadioButton id="btnRadio"
groupName="btnRadioSelect"
/>
</mx:Box>
当我运行应用程序时,单选按钮按其应有的方式显示在列中。但是,我无法仅选择其中一个单选按钮。我可以选择所有这些,但我不想要这个...我想要选择一个的能力,然后如果我选择另一个,那么第一个将被取消选择,当前的将被选中(就像您会期望单选按钮能够工作)。
我缺少什么?
I have a datagrid that I want to add a column of radio button using AS3 (instead of mxml). I was able to do this with a custom itemRenderer.
var dgc:DataGridColumn = new DataGridColumn();
dgc.itemRenderer = new ClassFactory(com.mypackage.RadioBtnColumnItemRenderer);
In my RadioBtnColumnItemRenderer.mxml, I have a box with a radioButton... like so:
<?xml version="1.0" encoding="utf-8"?>
<mx:Box
xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="center" verticalAlign="middle"
>
<mx:RadioButton id="btnRadio"
groupName="btnRadioSelect"
/>
</mx:Box>
When I run the application, the radio button shows up in the column as it should. However, I cannot select just ONE of the radio buttons. I am able to select all of them, but I don't want this... I want the ability to select one, and then if I select another one, then the first one is unselected and the current one becomes selected (just like you would expect radio buttons to work).
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你实际上很接近。您只需使用“properties”属性将对组的引用传递到类工厂中。
现在,在渲染器中,您需要在类似这样的地方设置该属性。
You're actually pretty close. You just need to pass the reference to the group into the class factory using the "properties" property.
Now in the renderer you need that property set somewhere like this.
您需要定义一个 RadioButtonGroup 才能使其仅选择一种行为。我认为如果您将此组放入项目渲染器中,您将无法实现所需的行为,因此您可能需要找到一种方法来从保存数据网格的容器中引用该组。
http://livedocs.adobe.com/flex/3/ langref/mx/controls/RadioButtonGroup.html
You'll need to define a RadioButtonGroup to have this select only one behavior. I think if you put this group in the item renderer, you won't be able to achieve the desired behavior though, so you may need to figure out a way to reference the group from the container holding the data grid.
http://livedocs.adobe.com/flex/3/langref/mx/controls/RadioButtonGroup.html