我有一个如下程序:
[Bindable]
private var myDP:Array = [
{label: "1", selected: true},
{label: "2", selected: false}
];
</mx:Script>
<mx:DataGrid dataProvider="{myDP}">
<mx:columns>
<mx:DataGridColumn dataField="label" headerText="Label" />
<mx:DataGridColumn dataField="selected" itemRenderer="mx.controls.CheckBox" />
</mx:columns>
</mx:DataGrid>
它工作正常,但是当复选框被更改时,该值不会在arraylist上更新。在此项呈示器上更改复选框时,有没有办法触发某些功能?
答案 0 :(得分:0)
在复选框更改事件中,您可以调度以下事件:
<s:CheckBox change="onChange()" />
private function onChange():void
{
var testEvent:CustomEvent = new CustomEvent(CustomEvent.SELECT_ITEM_EVENT,true);
CustomEvent.selectedItem = data;
dispatchEvent(selectEvent);
}
在主页中获取/添加EventListener事件:
addEventListener(CustomEvent.SELECT_ITEM_EVENT, this.selectFunction);
private function selectFunction(item:CustomEvent):void
{
// Your Action
}
希望它有所帮助。
答案 1 :(得分:0)
您的代码需要稍加修改;替换下面的代码行
<mx:DataGridColumn dataField="selected" itemRenderer="mx.controls.CheckBox" />
与
<mx:DataGridColumn dataField="selected" itemRenderer="itemRenderer.checkBoxRndr" />
并在项目'itemRenderer'中的项目中添加项目渲染器组件(比如'checkBoxRndr')。
项目-renderer将是,
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="20" verticalAlign="middle"
verticalGap="0" horizontalGap="0" horizontalAlign="center" verticalScrollPolicy="off" horizontalScrollPolicy="off"
paddingBottom="0" paddingLeft="0" paddingRight="0" paddingTop="0">
<mx:Script>
<![CDATA[
override public function set data(value:Object):void{
if(value != null){
super.data = value;
if(data.hasOwnProperty("selected") && data.selected != null){
rndrCheckBox.selected = data.selected;
}
}
}
private function onChange():void{
data.selected = rndrCheckBox.selected;
}
]]>
</mx:Script>
<mx:CheckBox id="rndrCheckBox" change="{onChange()}"/>
</mx:HBox>