DataGrid无法更新新行

时间:2012-11-14 12:22:39

标签: flex

我有以下功能,它将一个项目添加到数据库,然后返回到数据网格。数据管理方法是PHP。我的问题是数据库收到了新数据但数据网格没有新记录。

以下是代码的简化版本

    <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>

我已经尝试了serval方法来调试(button_clickHandler中的注释函数),但结果仍然相同。

我可以尝试其他任何方法吗?

1 个答案:

答案 0 :(得分:0)

您是否尝试刷新数据提供者?