这个问题让我发疯了,我真的需要你们的帮助。
我有一个显示从 mysql 查询的数据的数据网格。如果用户向数据库添加新记录,我正在尝试向我的数据网格添加一个新行。换句话说,我希望数据网格能够反映数据库中上传的数据。数据网格似乎只适用于我添加的第一条记录。如果我尝试添加第二条记录,则会添加新行,但它也会将第一行更改为新更新的记录。我知道这有点难以理解,所以我在这里画了一张图。
DATAGRID
id name number
1 test1 111
2 test2 222
假设我添加了一条新记录,数据网格将是
id name number
1 test1 111
2 test2 222
3 test3 333 //new record, works fine.
但如果我添加另一条记录,它将变成
id name number
1 test1 111
2 test2 222
4 test4 444 //old record, the values change to the newest record.
4 test4 444 //new record, but also change the previous record
如果我再次添加另一条记录,它将变为
id name number
1 test1 111
2 test2 222
5 test5 555 //first record, the values change to the newest record.
5 test5 555 //second record, the values change to the newest record.
5 test5 555 //newest record, change the previous 2 records
我已经做了任何我能想到的调试,但仍然没有运气。以下是我的代码:
// my php data service
<s:CallResponder id="addResult" result="addResult_resultHandler(event)" />
<script>
//The handler after the user click ADD button
protected function addBtn_clickHandler(event:MouseEvent):void
{
var newData:object = new Object();
newData.test1=formField1.text;
newData.test2=formField2.text;
newData.test3=formField3.text;
newData.test4=formField4.text;
addResult.token=Service.createJob(newData);
}
//the result handler for data service.
protected function addResult_resultHandler(event:ResultEvent):void
{
//jobData is my dataProvider in my datagrid component
//not sure why addItem() would mess me up so badly...
//newData is an Object created after user click the update
//button
jobDG.jobData.addItem(newData);
}
Mxml
<components:dataGridPanel id="jobDG"
jobData="{getJobsResult.lastResult}"/>
My datagrid component
mxml
<s:DataGrid id="dg" editable="true" x="5" y="3" width="734" height="253">
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="test1" headerText="text1">
</s:GridColumn>
<s:GridColumn dataField="test2" headerText="text2">
</s:GridColumn>
<s:GridColumn dataField="test3" headerText="text3">
</s:GridColumn>
<s:GridColumn dataField="test4" headerText="text4">
</s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object text1="aaaaa" text2="bbbbb" text3="ccccc" text4="dddddd">
</fx:Object>
</s:typicalItem>
<s:AsyncListView list="{jobData}" />
</s:DataGrid>
我现在真的很绝望。任何帮助将不胜感激。