2011-08-08 3 views
0

私はこの2日間、この問題を解こうとしていましたが、Flex開発者の標準的な出来事だと思います。私はPHP Zend webserviceフレームワークでFlex 4.5を使用しています。基本的には、2つのDataGridをドラッグアンドドロップすることができます。コンポーネントの初期化時に、Webサービスを呼び出して、DataGridにデータを格納します。次に、ユーザーは行を下のDataGridにドラッグして、後で処理して保存することができます。Flex PHP WebServiceの結果からDataGridレコードをリセット

私の問題は、ユーザーがViewStackの新しいコンポーネントに移動するリセットボタン(またはキャンセルボタン)を持っていて、DataGridでコンポーネントに戻ると、DataGridの元のレコードと下部のDataGridは空です。私は、トップDataGridを再構築するための良い方法を理解できません。私はそれをクリアすることができますが、それは元のデータで更新されていないようです。

Webサービスをもう一度呼び出すのに失敗してしまい、dataproviderを新しいlastResultトークンに設定しようとしました。また、最初のWebサービス呼び出しの結果を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

可能であれば、sparkデータグリッドを使用する必要があります。それはずっと速くなります。

しかし、本質的には、サービスのlastResultを直接データグリッドにバインドしていることが主な問題です。あなたがしなければならないことは、その結果をあなたのクラスのどこかに保存し、変更された未保存のバージョンとオリジナルを持つようにデータをコピーすることです。そこから元のデータ(yourDatagrid.dataProvider = originalData;)に戻すのは簡単です。これについて私のblog articleをチェックしてください。

+0

パーフェクト。ありがとうございました!そのような簡単な解決策とそれは2 +混乱の日の費用がかかります。 :) – Tabnaka

関連する問題