我有一个可编辑属性设置为 true 的数据网格。当我对数据进行更改时,数据提供程序中的数据不会被修改。如何将更改应用到数据提供者?我是 Flex 的新手,有人可以就此提出建议吗?
问问题
408 次
1 回答
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>
于 2013-06-13T16:07:44.483 回答