2011-08-08 2 views
0

지난 2 일 동안 Flex 개발자를위한 표준 문제라고 생각한이 문제를 해결하기 위해 노력했습니다. 나는 PHP 젠드 webservice 프레임 워크와 플렉스 4.5를 사용하고 있습니다. 기본적으로 서로 드래그 앤 드롭 할 수있는 2 개의 DataGrid가 있습니다. 구성 요소를 초기화 할 때 webservice를 호출하여 최상위 DataGrid를 채 웁니다. 그런 다음 사용자는 나중에 처리되고 저장되는 행 아래쪽 DataGrid로 드래그 할 수 있습니다.Flex PHP WebService 결과에서 DataGrid 레코드 재설정

내 문제는 사용자를 ViewStack의 새 구성 요소로 이동시키는 재설정 버튼 (또는 취소 버튼)을 갖고 싶습니다. DataGrid를 사용하여 구성 요소로 돌아 오면 최상위 DataGrid에 원본 레코드 및 아래쪽 DataGrid가 비어 있습니다. 난 그냥 최고의 DataGrid repopulate 좋은 방법을 알아낼 수 없습니다. 나는 그것을 지울 수는 있지만 원래의 데이터로 새로 고치는 것 같지 않습니다.

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

가능한 경우 spark datagrid를 사용해야합니다. 훨씬 빨라졌습니다.

하지만 근본적인 문제는 서비스의 lastResult를 직접 DataGrid에 바인딩하기 때문입니다. 당신이해야 할 일은 그 결과를 당신의 클래스 어딘가에 저장하고 수정 된, 저장되지 않은 버전과 원본을 갖도록 데이터를 복사하는 것입니다. 거기서 원 데이터 (yourDatagrid.dataProvider = originalData;)로 되돌아가는 것이 쉽습니다. 이 문제에 대해 blog article을 확인하십시오.

+0

Perfect. 고맙습니다! 이러한 쉬운 솔루션과 그것은 혼란의 2 일 이상의 비용. :) – Tabnaka