我一直被困在最後2天試圖找出這個問題,我認爲這是Flex開發人員的標準事件。我使用Flex 4.5和PHP Zend web服務框架。基本上,我有2個DataGrids可以相互拖放。在組件的初始化過程中,我調用webservice來填充頂部的DataGrid。然後用戶可以將行拖動到底部的DataGrid中,稍後進行處理和保存。Flex PHP重置來自WebService結果的DataGrid記錄
我的問題是,我想要一個重置按鈕(或取消按鈕),將用戶到ViewStack中的新組件,並且如果他們返回與DataGrids的組件,頂部的DataGrid具有原始記錄和底部DataGrid是空的。我只是無法找出重新填充頂級DataGrid的好方法。我可以清除它,但它似乎沒有刷新原始數據。
我試過再次調用webservice失敗並將數據提供者設置爲新的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>
完美。謝謝!這樣一個簡單的解決方案,它花費我2天以上的困惑。 :) – Tabnaka