我正在使用Flash Builder 4.6中的付款跟踪移动应用。我正在使用Flex数据管理系统。我的问题很少,如下所述:
代码(AddEditView)
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:valueObjects="valueObjects.*"
xmlns:studentsservice="services.studentsservice.*"
title="Add Student" add="view1_addHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function saveBtn_clickHandler(event:MouseEvent):void
{
if (currentState=="Add"){
var students:Students = new Students();
students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text;
createStudentsResult.token = studentsService.createStudents(students);
studentsService.commit();
} else {
/* updateStudentsResult.token = studentsService.updateStudents(students);
studentsService.getDataManager(studentsService.DATA_MANAGER_STUDENTS).autoCommit=false; */
/* students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text; */
updateStudentsResult.token = studentsService.updateStudents(students);
/* studentsService.getDataManager(studentsService.DATA_MANAGER_STUDENTS).autoCommit=false */;
}
}
protected function createStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.replaceView(StudentDetail,event.result as int);
}
protected function cancelBtn_clickHandler(event:MouseEvent):void
{
navigator.popView();
studentsService.commit();
}
protected function view1_addHandler(event:FlexEvent):void
{
if(data == null){
currentState ="Add";
} else {
currentState ="Edit";
students = data as Students;
title ="Edit Student";
}
}
protected function updateStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.popView();
}
]]>
</fx:Script>
<s:states>
<s:State name="Add"/>
<s:State name="Edit"/>
</s:states>
<fx:Declarations>
<valueObjects:Students id="students"/>
<s:CallResponder id="createStudentsResult" result="createStudentsResult_resultHandler(event)"/>
<studentsservice:StudentsService id="studentsService"/>
<s:CallResponder id="updateStudentsResult" result="updateStudentsResult_resultHandler(event)"/>
</fx:Declarations>
<s:actionContent>
<s:Button id="cancelBtn" label="Cancel" click="cancelBtn_clickHandler(event)"/>
<s:Button id="saveBtn" label="Save" click="saveBtn_clickHandler(event)"/>
</s:actionContent>
<s:Scroller left="0" right="0" top="0" bottom="0">
<s:VGroup width="100%" paddingLeft="10" paddingRight="10">
<s:Label paddingTop="15" text="First Name"/>
<s:TextInput id="firstnameTextInput" width="100%" text="@{students.firstname}"/>
<s:Label paddingTop="15" text="Last Name"/>
<s:TextInput id="lastnameTextInput" width="100%" text="@{students.lastname}"/>
<s:Label paddingTop="15" text="Cellphone"/>
<s:TextInput id="cellphoneTextInput" width="100%" text="@{students.cellphone}"/>
<s:Label paddingTop="15" text="Email"/>
<s:TextInput id="emailTextInput" width="100%" text="@{students.email}"/>
<s:Label paddingTop="15" text="Address"/>
<s:TextInput id="addressTextInput" width="100%" text="@{students.address}"/>
<s:Label paddingTop="15" text="Class ID"/>
<s:TextInput id="classidTextInput" width="100%" text="{students.class_id}"/>
<s:Label paddingTop="15" text="Photo file"/>
<s:TextInput id="photofileTextInput" width="100%" text="@{students.photofile}"/>
</s:VGroup>
</s:Scroller>
</s:View>
代码(StudentView)
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:valueObjects="valueObjects.*"
xmlns:studentsservice="services.studentsservice.*"
title="Add Student" add="view1_addHandler(event)">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import mx.rpc.events.ResultEvent;
protected function saveBtn_clickHandler(event:MouseEvent):void
{
if (currentState=="Add"){
var students:Students = new Students();
students.firstname = firstnameTextInput.text;
students.lastname = lastnameTextInput.text;
students.cellphone = cellphoneTextInput.text;
students.email = emailTextInput.text;
students.address = addressTextInput.text;
students.class_id = parseInt(classidTextInput.text);
students.photofile = photofileTextInput.text;
createStudentsResult.token = studentsService.createStudents(students);
studentsService.commit();
} else {
updateStudentsResult.token = studentsService.updateStudents(students);
}
}
protected function createStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.replaceView(StudentDetail,event.result as int);
}
protected function cancelBtn_clickHandler(event:MouseEvent):void
{
navigator.popView();
studentsService.commit();
}
protected function view1_addHandler(event:FlexEvent):void
{
if(data == null){
currentState ="Add";
} else {
currentState ="Edit";
students = data as Students;
title ="Edit Student";
}
}
protected function updateStudentsResult_resultHandler(event:ResultEvent):void
{
navigator.popView();
}
]]>
</fx:Script>
<s:states>
<s:State name="Add"/>
<s:State name="Edit"/>
</s:states>
<fx:Declarations>
<valueObjects:Students id="students"/>
<s:CallResponder id="createStudentsResult" result="createStudentsResult_resultHandler(event)"/>
<studentsservice:StudentsService id="studentsService"/>
<s:CallResponder id="updateStudentsResult" result="updateStudentsResult_resultHandler(event)"/>
</fx:Declarations>
<s:actionContent>
<s:Button id="cancelBtn" label="Cancel" click="cancelBtn_clickHandler(event)"/>
<s:Button id="saveBtn" label="Save" click="saveBtn_clickHandler(event)"/>
</s:actionContent>
<s:Scroller left="0" right="0" top="0" bottom="0">
<s:VGroup width="100%" paddingLeft="10" paddingRight="10">
<s:Label paddingTop="15" text="First Name"/>
<s:TextInput id="firstnameTextInput" width="100%" text="@{students.firstname}"/>
<s:Label paddingTop="15" text="Last Name"/>
<s:TextInput id="lastnameTextInput" width="100%" text="@{students.lastname}"/>
<s:Label paddingTop="15" text="Cellphone"/>
<s:TextInput id="cellphoneTextInput" width="100%" text="@{students.cellphone}"/>
<s:Label paddingTop="15" text="Email"/>
<s:TextInput id="emailTextInput" width="100%" text="@{students.email}"/>
<s:Label paddingTop="15" text="Address"/>
<s:TextInput id="addressTextInput" width="100%" text="@{students.address}"/>
<s:Label paddingTop="15" text="Class ID"/>
<s:TextInput id="classidTextInput" width="100%" text="{students.class_id}"/>
<s:Label paddingTop="15" text="Photo file"/>
<s:TextInput id="photofileTextInput" width="100%" text="@{students.photofile}"/>
</s:VGroup>
</s:Scroller>
</s:View>
如果有人曾经解决过类似的问题,请通过此指导我。提前谢谢。
答案 0 :(得分:0)
我的怀疑studentsService.commit();将数据保存到数据库中,如果currentState ='edit',则此代码无法访问。所以,在else块中你也必须做一个studentsService.commit();
答案 1 :(得分:0)
您是否尝试在服务对象(RemoteObject)上添加“invoke”,“result”或“fault”的侦听器以查明发生了什么? 我认为请求没有按你的意愿发送。查看FaultEvent了解更多详情。