0
我有以下函數將項目添加到數據庫,然後返回到數據網格。數據管理方法是PHP。和我的問題是數據庫已收到新的數據,但數據網格沒有新的記錄。DataGrid無法更新新行
這裏是我試圖調試藪方法(在button_clickHandler註釋的功能)的代碼
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.CloseEvent;
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
import spark.events.GridItemEditorEvent;
protected function dataGrid_creationCompleteHandler(event:FlexEvent):void
{
getAllUserResult.token = userService.getAllUser();
}
protected function button_clickHandler(event:MouseEvent):void
{
var user:User = new User();
user.idUser = parseInt(idUserTextInput.text);
user.userName = userNameTextInput.text;
user.password = passwordTextInput.text;
createUserResult.token = userService.createUser(user);
userService.commit();
//getAllUserResult.token = userService.getAllUser();
//dataGrid.invalidateDisplayList();
//var e:FlexEvent;
//dataGrid_creationCompleteHandler(e);
//user.idUser=createUserResult.token.result as int;
//dataGrid.dataProvider.addItem(user);
this.currentState="State1";
}
</fx:Script>
<s:states>
<s:State name="State1"/>
<s:State name="Add"/>
</s:states>
<fx:Declarations>
<s:CallResponder id="getAllUserResult"/>
<userservice:UserService id="userService"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<valueObjects:User id="user"/>
<s:CallResponder id="createUserResult"/>
</fx:Declarations>
<s:DataGrid id="dataGrid" includeIn="State1" x="95" y="10" width="961" height="505"
creationComplete="dataGrid_creationCompleteHandler(event)" editable="true"
gridItemEditorSessionSave="dataGrid_gridItemEditorSessionSaveHandler(event)"
requestedRowCount="4" >
<s:columns>
<s:ArrayList>
<s:GridColumn dataField="idUser" headerText="idUser"></s:GridColumn>
<s:GridColumn dataField="userName" headerText="userName"></s:GridColumn>
<s:GridColumn dataField="password" headerText="password"></s:GridColumn>
</s:ArrayList>
</s:columns>
<s:typicalItem>
<fx:Object idUser="idUser1" Name="Name1" password="password1"></fx:Object>
</s:typicalItem>
<s:AsyncListView list="{getAllUserResult.lastResult}"/>
</s:DataGrid>
<s:Button id="button" includeIn="Add" x="695" y="407" label="CreateUser"
click="button_clickHandler(event)"/>
<s:Form includeIn="Add" x="74" y="21" width="343" height="362">
<s:FormItem width="200" label="IdUser">
<s:helpContent >
<s:VGroup>
<s:Label width="76" height="42" text="Auto Generate"></s:Label>
</s:VGroup>
</s:helpContent>
<s:Label id="idUserTextInput" text="{user.idUser}"/>
</s:FormItem>
<s:FormItem label="UserName" required="true">
<s:TextInput id="userNameTextInput" text="{user.userName}"/>
</s:FormItem>
<s:FormItem label="Password" required="true">
<s:TextInput id="passwordTextInput" text="{user.password}"/>
</s:FormItem>
</s:Form>
的簡化版本,但是,其結果仍然是相同的。
其他任何我可以嘗試的方法?
我有「//getAllUserResult.token = userService.getAllUser();」是我嘗試過的方法,不工作。 – Samuel