我有一个数据网格,其中editable属性设置为true。当我更改数据时,数据不会在数据提供程序中修改。如何将更改应用于数据提供者?我是Flex新手,有人可以就此提出建议吗?
答案 0 :(得分:0)
Hero就是一个例子,我已经测试过了。
您可以看到此文档http://livedocs.adobe.com/flex/3/html/help.html?content=celleditor_8.html
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
<mx:Script>
<![CDATA[
import mx.controls.TextInput;
import mx.events.DataGridEvent;
import mx.events.FlexEvent;
private var list:Array = [];//source dataProvider
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
list.push({name:"aaaa"}, {name:"bbbb"});
myDataGrid.dataProvider = list;
}
protected function myDataGrid_itemEditEndHandler(event:DataGridEvent):void
{
// TODO Auto-generated method stub
var targetDataGrid:DataGrid = event.target as DataGrid;
var newData:String = TextInput(targetDataGrid.itemEditorInstance).text;
var label:String = event.dataField;
//here according to target data type in list,you may force changing type of newData, like int(newData)
var indexOfList:int = targetDataGrid.editedItemPosition.rowIndex;
list[indexOfList][label] = newData;
}
]]>
</mx:Script>
<mx:DataGrid id="myDataGrid" editable="true" itemEditEnd="myDataGrid_itemEditEndHandler(event)">
<mx:columns>
<mx:DataGridColumn dataField="name" headerText="Name" editable="true" />
</mx:columns>
</mx:DataGrid>