在 Adob​​e Flex 中创建一列单选按钮

发布于 2024-08-05 23:30:27 字数 3333 浏览 3 评论 0原文

我使用 itemRenderer 在 AdvancedDataGrid 列中创建单选按钮时出现不可预测的行为。类似问题已报告于 在 Adob​​e Flex 中创建单选按钮列。我尝试使用相同的过程,即将每个单选按钮 selectedValue 和 value 属性与关联 bean 的属性中指定的属性绑定,但仍然面临问题。

按钮更改值!所选择的 按钮变为取消选择状态,并且 未选中的将被选中。

这是我的 AdvancedDataGrid 的代码:

<mx:AdvancedDataGrid id="adDataGrid_rptdata" 
                width="100%" height="100%"
                dragEnabled="false" sortableColumns="false" 
                treeColumn="{action}"
                liveScrolling="false"
                displayItemsExpanded="true" >

                <mx:dataProvider>
                    <mx:HierarchicalData source="{this.competenceCollection}" childrenField="competenceCriteria"/>
                </mx:dataProvider>

                <mx:columns>
                    <mx:AdvancedDataGridColumn headerText="" id="action" dataField="criteriaName" />

                    <mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period1" value="{data}" selected="{data.period1}" group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>

                    <mx:AdvancedDataGridColumn headerText="Periode 2" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period2" value="{data}" selected="{data.period2}" group="{data.radioBtnGrpArray[1]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>

                    <mx:AdvancedDataGridColumn headerText="Periode 3" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period3" value="{data}" selected="{data.period3}" group="{data.radioBtnGrpArray[2]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>
                </mx:columns>
            </mx:AdvancedDataGrid>

在这方面,任何解决方法都受到高度赞赏!

I am having an un-predictable behavior of creating radio buttons in advancedDataGrid column using itemRenderer. Similar kind of problem has been reported at
Creating a column of RadioButtons in Adobe Flex. I tried to use the same procedure i.e. bind every radio button selectedValue and value attributes with the property specified in the property of the associated bean but still facing the problem.

The button change values! The selected
button becomes deselected, and
unselected ones become selected.

Here is the code of my advancedDataGrid:

<mx:AdvancedDataGrid id="adDataGrid_rptdata" 
                width="100%" height="100%"
                dragEnabled="false" sortableColumns="false" 
                treeColumn="{action}"
                liveScrolling="false"
                displayItemsExpanded="true" >

                <mx:dataProvider>
                    <mx:HierarchicalData source="{this.competenceCollection}" childrenField="competenceCriteria"/>
                </mx:dataProvider>

                <mx:columns>
                    <mx:AdvancedDataGridColumn headerText="" id="action" dataField="criteriaName" />

                    <mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period1" value="{data}" selected="{data.period1}" group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>

                    <mx:AdvancedDataGridColumn headerText="Periode 2" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period2" value="{data}" selected="{data.period2}" group="{data.radioBtnGrpArray[1]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>

                    <mx:AdvancedDataGridColumn headerText="Periode 3" dataField="" width="200">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox horizontalAlign="center" width="100%" verticalAlign="middle">                                  
                                    <mx:RadioButton name="period3" value="{data}" selected="{data.period3}" group="{data.radioBtnGrpArray[2]}" visible="{data.showRadioButton}" />
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:AdvancedDataGridColumn>
                </mx:columns>
            </mx:AdvancedDataGrid>

Any work around is highly appreciated in this regard!

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

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

发布评论

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

评论(1

原来分手还会想你 2024-08-12 23:30:27

选定的按钮变为取消选定状态,未选定的按钮变为选定状态。

此问题是否仅发生在那些选择状态由用户手动更改的单选按钮上?在这种情况下,这是因为当重用 RadioButton 时,flex 根据声明中提到的值重置其 selected 状态。因此,即使您选择/取消选择 periode 1 列中的比率按钮,当您滚动并返回时,flex 也会将其重置为 {data.period1}。使列可编辑以将修改保存回数据提供者可能会起作用。尝试将列声明更改为:

<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200" 
     editable="true" rendererIsEditor="true" editorDataField="selected">

编辑:尝试此 - 尝试在选择单选按钮时更改数据提供程序。从内存编写且未经测试的代码 - 可能包含错误。

<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
  <mx:itemRenderer>
    <mx:Component>
      <mx:HBox horizontalAlign="center" width="100%"
        verticalAlign="middle">
        <mx:RadioButton id="rb" name="period1" value="{data}" 
          selected="{data.period1}" 
          group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" 
          change="outerDocument.handleRadio1(this);"/>
      </mx:HBox>
    </mx:Component>
  </mx:itemRenderer>
</mx:AdvancedDataGridColumn>
//in a script tag outside the datagrid.
public function handleRadio1(renderer:IListItemRenderer):void
{
  var index:Number = adDataGrid_rptdata.itemRendererToIndex(renderer);
  this.competenceCollection[i].period1 = renderer.rb.selected;
}

The selected button becomes deselected, and unselected ones become selected.

Is this problem occurring only for those radio buttons whose selected state was manually changed by the user? In that case it is because flex resets its selected state based on the value mentioned in the declaration when a RadioButton is reused. So even if you select/deselect a ratio button in the Periode 1 column, flex resets it to {data.period1} when you scroll away and come back. Making the column editable to save the modifications back to the data provider might work. Try changing the column declaration to:

<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200" 
     editable="true" rendererIsEditor="true" editorDataField="selected">

EDIT: Try this - attempting to change the data provider when the radio button is selected. code written from memory and not tested - might contain bugs.

<mx:AdvancedDataGridColumn headerText="Periode 1" dataField="" width="200">
  <mx:itemRenderer>
    <mx:Component>
      <mx:HBox horizontalAlign="center" width="100%"
        verticalAlign="middle">
        <mx:RadioButton id="rb" name="period1" value="{data}" 
          selected="{data.period1}" 
          group="{data.radioBtnGrpArray[0]}" visible="{data.showRadioButton}" 
          change="outerDocument.handleRadio1(this);"/>
      </mx:HBox>
    </mx:Component>
  </mx:itemRenderer>
</mx:AdvancedDataGridColumn>
//in a script tag outside the datagrid.
public function handleRadio1(renderer:IListItemRenderer):void
{
  var index:Number = adDataGrid_rptdata.itemRendererToIndex(renderer);
  this.competenceCollection[i].period1 = renderer.rb.selected;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文