开发者

Data grid crashes with data provider change

开发者 https://www.devze.com 2023-01-19 00:20 出处:网络
I have a radio button group within a data grid, whenever I attempt to change the selectedradi开发者_运维百科o button the web page crashes. Below is how I put together the radio button in the data grid

I have a radio button group within a data grid, whenever I attempt to change the selected radi开发者_运维百科o button the web page crashes. Below is how I put together the radio button in the data grid. Anyone see what could be the cause of the issue?

MXML

<mx:Accordion>
<fx:Declarations>
<s:RadioButtonGroup id="cover"/>
</fx:Declarations>
<fx:Script>
<![CDATA[[
[Bindable] public var arrColl = new ArrayCollection();
arrColl.addItem(new ObjectProxy({name:"Jon Doe", position:1, cover:true, group:cover}));
arrColl.addItem(new ObjectProxy({name:"John Smith", position:2, cover:true, group:cover}));
]]>
</fx:Script>
<fx:Binding source="{dg.dataProvider as ArrayCollection}" destination="{arrColl}"/>
<mx:DataGrid id="dg" dataProvider="{arrColl}" ..>
...
</mx:DataGrid>

Renderer

<?xml version="1.0" encoding="utf-8"?>
<s:MXDataGridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"                    xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" 
focusEnabled="true">
<fx:Script>
<![CDATA[
import mx.events.DynamicEvent;
public function selection(event:MouseEvent):void
{
var selectionEvt:DynamicEvent = new DynamicEvent("selectionEvt", true);
selectionEvt.data = this.data;
dispatchEvent(selectionEvt);
}
]]>
</fx:Script>
<s:RadioButton label="Cover" group="{data.group}" selected="{data.cover}" click="selection(event)"/>
</s:MXDataGridItemRenderer>

Radio Button Selection Event Handler

private function updateDp(event:DynamicEvent):void
{
if (event.type == "selectionEvt")
{
for (var i:int = 0; i < editGrid.dataProvider.length; i++) 
{
editGrid.dataProvider.getItemAt(i).cover = false; // Unselect all members of radio button group 
}
var index:int = editGrid.dataProvider.getItemIndex(event.data);
editGrid.dataProvider.getItemAt(index).cover = true; // Select target radio button
}


I got the code to work by using the radio button group's change event, rather than a custom/dynamic event within the radio button item renderer. However, I still don't quite understand (if/why) using the dynamic events caused the problem.


I had a similar issue once but can't seem to recall how I resolved as it was quite some time ago.

0

精彩评论

暂无评论...
验证码 换一张
取 消