我有一个单选按钮列表,我希望能够以编程方式设置 的值,并让用户手动设置 的值。
我有一小部分数据项,我想将其显示为单选按钮列表中的选项。这些对象存储在模型对象中,就像当前选定的项目一样。当前选定的项目绑定到单选按钮组。单选按钮是使用火花列表生成的。
我在以编程方式设置列表时遇到问题 - 每当我将单选按钮组上的当前值设置为列表中的第一个值时,所有单选按钮都会被清除,其中应选择第一个单选按钮。我在检查调试器时,发现了可能的原因 - 组中有两个单选按钮指向相同的值,其中一个没有显示。我最好的猜测是列表控件创建了一个额外的项目渲染器,它会保留该渲染器以备需要滚动列表时使用。
有没有一种方法可以在不使用列表的情况下基于 ArrayCollection 创建单选按钮?如果做不到这一点,是否可以阻止列表生成额外的项目?
I have a list of radio buttons, which I want to be able to both set the value of programmatically and for the user to set the value of manually.
I have a small list of data items which I want to display as options in a list of radio buttons. The objects are stored in a model object, as is the currently selected item. The currently selected item is bound to the radiobutton group. The radio buttons are generated using a spark list.
I am having a problem setting the list programatically - whenever I set the current value on the radiobutton group to the first value in the list, all of the radio buttons are cleared, where the first one should be selected. I when checking in the debugger, I found the likely reason - there are two radiobuttons in the group that point to the same value, one of which isn't showing. My best guess is that the list control has created an extra item renderer which it is holding on to in case it needs to scroll the list.
Is there a way to create radioButtons based on an ArrayCollection without using a list? Failing that, is it possible to prevent the list from generating the extra item?
发布评论
评论(2)
最后,我给了 Spark 最佳实践手指并使用了中继器,它创建了正确数量的单选按钮,没有额外的内容。它可能很慢,但是对少于 10 个项目的集合的缓慢迭代是 O(我不在乎)。
In the end, I gave spark best practices the finger and used a repeater, which created the correct number of radioButtons with no extras. It may be slow, but slow iteration over a set of less than ten items is O(I don't care).
将
DataGroup
与 dataProvider(保存数据的对象的 ArrayList)结合使用,并使用自定义项渲染器来创建所需的单选按钮。将数据对象的正确绑定添加到单选按钮(甚至可以进行 2 路绑定以快速保存)。Use a
DataGroup
with a dataProvider (an ArrayList of objects holding data) with a custom item renderer that creates the radiobutton that you need. Add proper bindings of the data object to the radiobutton (maybe even do 2 way binding for quick saving).