Flex PHP从WebService结果重置DataGrid记录

时间:2011-08-08 20:21:32

标签: flex web-services zend-framework datagrid

过去两天我一直在努力解决这个问题,我认为这是Flex开发人员的标准事件。我正在使用Flex 4.5和PHP Zend webservice框架。基本上,我有2个可以在彼此之间拖放的DataGrids。在初始化组件时,我调用webservice来填充顶部DataGrid。然后,用户可以将行拖到底部的DataGrid中,以便稍后进行处理和保存。

我的问题是我想要一个重置按钮(或取消按钮),它将把用户带到ViewStack中的一个新组件,如果他们返回到带有DataGrids的组件,那么顶级DataGrid会有原始组件记录和底部DataGrid是空的。我只是想不出重新填充顶级DataGrid的好方法。我可以清除它,但它似乎没有刷新原始数据。

我尝试再次调用webservice并将dataprovider设置为新的lastResult标记失败了。我还尝试将初始webservice调用的结果复制到ArrayCollection并简单地将Bindable变量设置为该ArrayCollection(或者是保存原始记录的ArrayCollection的备份)。有人有一个简单的解决方案吗?谢谢!

    <?xml version="1.0" encoding="utf-8"?>
    <s:NavigatorContent xmlns:fx="http://ns.adobe.com/mxml/2009"
                        xmlns:s="library://ns.adobe.com/flex/spark"
                        xmlns:mx="library://ns.adobe.com/flex/mx"
                        xmlns:valueObjects="valueObjects.*"
                        xmlns:usersservicecreatetherapist="services.usersservicecreatetherapist.*"
                        width="910" height="894" backgroundColor="#F4F79B"
                        currentState="createTherapistState"
                        fontSize.createTherapistState="16">
        <s:layout>
            <s:BasicLayout/>
        </s:layout>
        <fx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.controls.Alert;
                import mx.events.CloseEvent;
                import mx.events.FlexEvent;
                import mx.rpc.AsyncToken;
                import mx.rpc.IResponder;
                import mx.rpc.events.FaultEvent;
                import mx.rpc.events.ResultEvent;
                import mx.rpc.remoting.mxml.RemoteObject;

                import spark.events.IndexChangeEvent;

                protected function process_therapistDetailsForm():void
                {
                    currentState="reviewTherapistState";
                }

                protected function cancel_therapistDetailsForm():void
                {
                    resetCreateTherapistFormsGrids();
                    parentDocument.switchView("overviewComponent");

                }

                protected function patientGridInitialize():void
                {   
                    getUsersByUserType('Active');

                }

                // Reset functions
                protected function resetCreateTherapistFormsGrids():void
                {
                    // logic to reset grid ??

                }


                protected function getUsersByUserType(userStatus:String):void
                {
                    getUsersByUserTypeResult.token = usersServiceCreateTherapist.getUsersByUserType(userStatus);
                }

            ]]>
        </fx:Script>
        <s:states>
            <s:State name="createTherapistState"/>
            <s:State name="reviewTherapistState"/>
        </s:states>
        <fx:Declarations>   
            <s:ArrayCollection id="genderArray">
                <fx:String>Male</fx:String>
                <fx:String>Female</fx:String>
            </s:ArrayCollection>

            <s:ArrayCollection id="usStatesAbbrArray">
                <fx:String>AK</fx:String>
                <fx:String>AL</fx:String>
                <fx:String>AR</fx:String>
                <fx:String>AZ</fx:String>
                <fx:String>CA</fx:String>
                <fx:String>CO</fx:String>
                <fx:String>CT</fx:String>
                <fx:String>DC</fx:String>
                <fx:String>DE</fx:String>
                <fx:String>FL</fx:String>
                <fx:String>GA</fx:String>
                <fx:String>HI</fx:String>
                <fx:String>IA</fx:String>
                <fx:String>ID</fx:String>
                <fx:String>IL</fx:String>
                <fx:String>IN</fx:String>
                <fx:String>KS</fx:String>
                <fx:String>KY</fx:String>
                <fx:String>LA</fx:String>
                <fx:String>MA</fx:String>
                <fx:String>MD</fx:String>
                <fx:String>ME</fx:String>
                <fx:String>MI</fx:String>
                <fx:String>MN</fx:String>
                <fx:String>MO</fx:String>
                <fx:String>MS</fx:String>
                <fx:String>MT</fx:String>
                <fx:String>NC</fx:String>
                <fx:String>ND</fx:String>
                <fx:String>NE</fx:String>
                <fx:String>NH</fx:String>
                <fx:String>NJ</fx:String>
                <fx:String>NM</fx:String>
                <fx:String>NV</fx:String>
                <fx:String>NY</fx:String>
                <fx:String>OH</fx:String>
                <fx:String>OK</fx:String>
                <fx:String>OR</fx:String>
                <fx:String>PA</fx:String>
                <fx:String>PR</fx:String>
                <fx:String>RI</fx:String>
                <fx:String>SC</fx:String>
                <fx:String>SD</fx:String>
                <fx:String>TN</fx:String>
                <fx:String>TX</fx:String>
                <fx:String>UT</fx:String>
                <fx:String>VT</fx:String>
                <fx:String>VA</fx:String>
                <fx:String>WA</fx:String>
                <fx:String>WI</fx:String>
                <fx:String>WV</fx:String>
                <fx:String>WY</fx:String>
            </s:ArrayCollection>
            <s:CallResponder id="getUsersByUserTypeResult"/>
            <usersservicecreatetherapist:UsersServiceCreateTherapist id="usersServiceCreateTherapist"
                                                                     fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
                                                                     showBusyCursor="true"/>

        </fx:Declarations>

        <!-- Step 1: Fill out form of patient details -->
        <s:Scroller left="10" top="10" bottom="0" 
                    width="450">
            <s:VGroup width="100%" height="100%">
                <s:Form id="therapistDetailsForm" 
                        width="100%" 
                        color="#2582A4"
                        enabled.reviewTherapistState="false">
                    <s:FormHeading width="358" 
                                   label="Step 1: Create a new therapist" 
                                   fontWeight="normal"/>
                    <s:FormItem width="100%"
                                label="First Name" 
                                fontSize="14"
                                required="true">
                        <s:TextInput id="firstName" 
                                     width="100%"/>
                    </s:FormItem>
                    <s:FormItem width="100%" 
                                label="Middle Name" 
                                fontSize="14">
                        <s:TextInput id="middleName"
                                     width="100%"/>
                    </s:FormItem>
                    <s:FormItem width="100%" 
                                label="Last Name" 
                                fontSize="14"
                                required="true">
                        <s:TextInput id="lastName" 
                                     width="100%"/>
                    </s:FormItem>
                    <s:HGroup width="100%" 
                              height="55">
                        <s:FormItem width="50%" 
                                    label="Gender" 
                                    fontSize="14"
                                    required="true">
                            <s:DropDownList id="gender"
                                            dataProvider="{genderArray}"
                                            selectedIndex="0"/>
                        </s:FormItem>
                        <s:FormItem width="50%" 
                                    label="D.O.B." 
                                    fontSize="14"
                                    required="true">
                            <s:TextInput id="birthday"
                                         width="100%"/>
                        </s:FormItem>
                    </s:HGroup>
                    <s:HGroup width="100%" height="55">
                        <s:FormItem width="50%" 
                                    label="Email" 
                                    fontSize="14"
                                    required="true">
                            <s:TextInput id="email"
                                         width="100%"/>
                        </s:FormItem>                   
                        <s:FormItem width="50%" 
                                    label="Phone" 
                                    fontSize="14"
                                    required="true">
                            <s:TextInput id="phone"
                                         width="100%"/>
                        </s:FormItem>

                    </s:HGroup>
                    <s:FormItem width="90%" height="47" 
                                label="Address" 
                                fontSize="14"
                                required="true">
                        <s:TextInput id="address" 
                                     width="100%"/>
                    </s:FormItem>
                    <s:FormItem width="90%" height="47" 
                                label="City" 
                                fontSize="14"
                                required="true">
                        <s:TextInput id="city" 
                                     width="100%"/>
                    </s:FormItem>
                    <s:HGroup width="100%" height="52">
                        <s:FormItem width="50%" 
                                    label="State" 
                                    fontSize="14"
                                    required="true">
                            <s:DropDownList id="usStates"
                                            dataProvider="{usStatesAbbrArray}"
                                            selectedIndex="20"/>
                        </s:FormItem>
                        <s:FormItem width="50%" 
                                    label="Zip" 
                                    fontSize="14"
                                    required="true">
                            <s:TextInput id="zip"
                                         width="100%"/>
                        </s:FormItem>
                    </s:HGroup>
                    <s:FormItem width="100%" 
                                label="Race" 
                                fontSize="14">
                        <s:TextInput id="race"
                                     width="100%"/>
                    </s:FormItem>
                    <s:FormItem width="100%" 
                                label="National Origin" 
                                fontSize="14">
                        <s:TextInput id="nationalOrigin"
                                     width="100%"/>
                    </s:FormItem>
                    <s:HGroup width="100%" height="52">
                        <s:FormItem width="50%" 
                                    label="Height " 
                                    fontSize="14"
                                    required="true">
                            <s:TextInput id="tHeight"
                                         width="78"/>
                        </s:FormItem>
                        <s:FormItem width="50%" 
                                    label="Weight" 
                                    fontSize="14">
                            <s:TextInput id="tWeight"
                                         width="100%"/>
                        </s:FormItem>
                    </s:HGroup>
                    <s:HGroup width="100%" height="50">
                        <s:FormItem>
                            <s:Button id="nextTherapistDetails"  x="501" y="50" label="Next"
                                      click="process_therapistDetailsForm();"/>
                        </s:FormItem>
                        <s:FormItem>
                            <s:Button id="cancelTherapistForm"  x="501" y="50" label="Cancel"
                                      click="cancel_therapistDetailsForm();"/>
                        </s:FormItem>
                    </s:HGroup>
                </s:Form>
            </s:VGroup>
        </s:Scroller>

        <s:Scroller includeIn="reviewTherapistState" right="10" top="10" bottom="0" width="442">
        <!-- Step 2: choose patients to be assigned to therapist -->
        <s:VGroup width="100%" height="100%">

            <s:Form id="assignPatientsForm" width="100%" height="436">
                <s:FormHeading label="Step 2: To assign patients drag them to bottom table."/>

                <!-- Drag and drop of the patients -->
                <mx:ApplicationControlBar width="402"
                                          horizontalAlign="center">
                    <s:Label text=" Available Active Patients"
                             color="#000000"
                             fontFamily="Verdana"/>
                </mx:ApplicationControlBar>

                <mx:DataGrid id="patientList" 
                             width="430" height="181" 
                             allowMultipleSelection="true"
                             color="#000000" 
                             dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" 
                             fontSize="14"
                             dataProvider="{getUsersByUserTypeResult.lastResult}">

                    <mx:columns>                    
                        <mx:DataGridColumn dataField="fname"  
                                           headerText="First Name" 
                                           width="100"/>        
                        <mx:DataGridColumn dataField="lname"  
                                           headerText="Last Name" 
                                           width="100"/>    
                        <mx:DataGridColumn dataField="birthday"
                                           headerText="D.O.B."
                                           width="95"/>                 
                        <mx:DataGridColumn dataField="gender" 
                                           headerText="Gender"
                                           width="70"/>                 
                        <mx:DataGridColumn dataField="weight" 
                                           headerText="Weight"
                                           width="65"/>                 
                    </mx:columns>               
                </mx:DataGrid>

                <s:HGroup width="100%" height="155">
                    <mx:DataGrid id="selectedPatientList" 
                                 width="300" height="154"
                                 allowMultipleSelection="true" 
                                 dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" 
                                 color="#000000"
                                 creationComplete="patientGridInitialize();" 
                                 fontSize="14">

                        <mx:columns>                    
                            <mx:DataGridColumn dataField="fname"  
                                               headerText="First Name" />   
                            <mx:DataGridColumn dataField="lname"  
                                               headerText="Last Name" />
                        </mx:columns>               
                    </mx:DataGrid>
                    <s:VGroup width="100%">

                        <s:FormItem width="100%">
                            <s:Button id="saveTherapistForm" y="50" left="0" right="0" label="Save"
                                      click="process_therapistDetailsForm();"/>
                        </s:FormItem>
                        <s:FormItem width="100%">
                            <s:Button id="backTherapistDetails" y="50" left="0" right="0" label="Go Back"
                                      click="currentState='createTherapistState';"/>
                        </s:FormItem>
                        <s:FormItem width="100%">
                            <s:Button id="cancelTherapistForm2" y="50" left="0" right="0" label="Cancel"
                                      click="cancel_therapistDetailsForm();"/>
                        </s:FormItem>
                    </s:VGroup>
                </s:HGroup>
            </s:Form>
        </s:VGroup>
        </s:Scroller>


    </s:NavigatorContent>

1 个答案:

答案 0 :(得分:1)

如果可以,您应该使用spark datagrid。使它快得多。

但实质上,您的主要问题是因为您将服务的lastResult直接绑定到datagrid。您应该做的是将结果保存在类中的某个位置并复制数据,以便您拥有修改后的未保存版本和原始版本。从那里可以很容易地回到原始数据(yourDatagrid.dataProvider = originalData;)。请查看我的blog article