我对 Datagrid 有以下问题。我有一个可以更改客户端的组合框,一旦选择了客户端,系统就会使用具有 CheckBox 和两个单选按钮的 ItemRenderer 填充 Datagrid。我第一次填充列表时,一切正常。
当我更改客户端并触发事件以更改此类 Datagrid 的内容时,问题就出现了。Datagrid dataProvider 被重新声明为新的 ArrayCollection 并迭代填充新信息。
问题是复选框的状态保持不变,尽管内容发生了变化。
这里发生了什么?我不明白。
编辑:
private function showProductosTable(evt:ResultEvent, token:Object):void {
precioClienteModel.modelo.arrayPanelPrecioCliente = new ArrayCollection;
for each(var data:Object in evt.result as ArrayCollection) {
var pc:PanelPrecioClienteDatatype = new PanelPrecioClienteDatatype;
pc.ID = data.ID;
pc.clienteID = data.clienteID;
pc.productoID = data.productoID;
pc.producto = data.producto;
pc.proveedorID = data.proveedorID;
pc.proveedor = data.proveedor;
pc.productos_proveedorID = data.productos_proveedorID;
pc.cantidad_80 = data.cantidad_80;
pc.cantidad_100 = data.cantidad_100;
pc.kg_caja_80 = data.kg_caja_80;
pc.kg_caja_100 = data.kg_caja_100;
precioClienteModel.modelo.arrayPanelPrecioCliente.addItem(pc);
// Comprobamos si ya tenemos metido el ProductoID en nuestra Columna de Productos
if ( !precioClienteModel.checkIfProductIDInList( pc.productoID ) ) {
precioClienteModel.modelo.arrayColumnaProductos.addItem( {'productoID':pc.productoID, 'producto':pc.producto,
'proveedor1': {'value':0, 'selected':false},
'proveedor2': {'value':0, 'selected':false},
'proveedor3': {'value':0, 'selected':false},
'proveedor4': {'value':0, 'selected':false},
'proveedor5': {'value':0, 'selected':false},
'proveedor6': {'value':0, 'selected':false},
'proveedor7': {'value':0, 'selected':false},
'proveedor8': {'value':0, 'selected':false},
'proveedor9': {'value':0, 'selected':false},
'proveedor10': {'value':0, 'selected':false},
'proveedor11': {'value':0, 'selected':false},
'proveedor12': {'value':0, 'selected':false},
'proveedor13': {'value':0, 'selected':false},
'proveedor14': {'value':0, 'selected':false},
'proveedor15': {'value':0, 'selected':false}} );
}
if ( !precioClienteModel.checkIfProveedorIDInList( pc.proveedorID ) ) {
precioClienteModel.modelo.arrayFilaProveedores.addItem( {'proveedorID':pc.proveedorID, 'proveedor':pc.proveedor} );
}
}
}
数据网格是:
<s:DataGrid id="preciosGrid" top="65" width="935" height="379" horizontalCenter="0" requestedRowCount="4"
dataProvider="{precioClienteModel.modelo.arrayColumnaProductos}">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="producto" headerText="Producto" width="150" editable="false"></s:GridColumn>
<s:GridColumn dataField="proveedor1" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor2" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor3" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor4" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor5" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor6" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor7" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor8" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor9" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor10" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor11" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor12" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor13" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor14" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
<s:GridColumn dataField="proveedor15" headerText="" width="52" editable="true" itemRenderer="renderers.PriceCellItemRenderer"></s:GridColumn>
</s:ArrayList>
</s:columns>
</s:DataGrid>
和 ItemRenderer:
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridListData;
import mx.controls.listClasses.BaseListData;
import spark.components.DataGrid;
private var _listData:BaseListData;
[Bindable]private var isSelected:Boolean = false;
override public function prepare(hasBeenRecycled:Boolean):void {
}
protected function lblData_doubleClickHandler(event:MouseEvent):void {
isSelected = !isSelected;
data[column.dataField]['selected'] = isSelected;
}
override public function set data( value:Object ) : void {
super.data = value;
if (value != null)
lblData.text = data[column.dataField]['value'];
}
[Bindable]public function get listData() : BaseListData {
return _listData;
}
public function set listData( value:BaseListData ) : void {
_listData = value;
}
]]>
</fx:Script>
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor color="{isSelected?0xCDCDCD:0xFFFFFF}"/>
</s:fill>
</s:Rect>
<s:Label id="lblData" width="100%" height="100%"
textAlign="center" verticalAlign="middle"
doubleClickEnabled="true" doubleClick="lblData_doubleClickHandler(event)"/>
谢谢。