FLEX在视图之间传递多个数据

编程入门 行业动态 更新时间:2024-10-11 19:16:35
FLEX在视图之间传递多个数据 - 使用接收的数据查询数据库(FLEX Pass Multiple data between views - Use received data to query database)

在我的flex移动项目中,我有2个视图

是一份调查清单 是调查问题列表

每个调查对象都有不同的问题,从视图1的列表中选择一个调查,并将记录ID传递给视图2,以根据ID查询数据。

我正在努力的方法是获取调查ID并将其传递给第2页的actionscript,我将从中检索参数化数据。

所有提示赞赏。

我的第1页代码

<?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:surveynameservice="services.surveynameservice.*" title="surveyMaster"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import spark.events.IndexChangeEvent; protected function list_creationCompleteHandler(event:FlexEvent):void { getAllSurveynameResult.token = surveynameService.getAllSurveyname(); } protected function surveySelected(event:IndexChangeEvent):void { // TODO Auto-generated method stub var tmpObj:Object = new Object(); tmpObj.sID = list.selectedItem.surveyID; tmpObj.sName = list.selectedItem.surveyName; (this.parentDocument as cp_dbHomeView).rightNav.activeView.data=tmpObj; } ]]> </fx:Script> <fx:Declarations> <s:CallResponder id="getAllSurveynameResult"/> <surveynameservice:SurveynameService id="surveynameService"/> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:List id="list" x="-1" y="0" width="171" height="100%" change="surveySelected(event)" creationComplete="list_creationCompleteHandler(event)" labelField="surveyName"> <s:AsyncListView list="{getAllSurveynameResult.lastResult}"/> </s:List> </s:View>

我的代码

<?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:surveyquestionsservice="services.surveyquestionsservice.*" creationComplete="init()" title="{data.sID}"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import spark.components.DataRenderer; public function init():void{ } protected function list_creationCompleteHandler(event:FlexEvent):void { getSurveyQuestionsResult.token = surveyquestionsService.getSurveyQuestions(data); } ]]> </fx:Script> <s:layout> <s:VerticalLayout paddingTop="15" paddingBottom="15" paddingLeft="15" paddingRight="15" gap="5" horizontalAlign="center" verticalAlign="top"/> </s:layout> <fx:Declarations> <s:CallResponder id="getSurveyQuestionsResult"/> <surveyquestionsservice:SurveyquestionsService id="surveyquestionsService"/> </fx:Declarations> <s:Label text="Click on a location on the left to explore!" visible="{data==null?true:false}"/> <s:Label text="Information about {this.data.surveyID}" visible="{data!=null?true:false}"/> <s:TextArea text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur accumsan felis ac tortor aliquam iaculis. Phasellus hendrerit viverra enim, sit amet scelerisque lectus dictum at. Aenean sodales nisi sed leo congue et porttitor ligula vehicula. Pellentesque turpis massa, suscipit vel fermentum quis, dignissim sed ipsum. Nulla aliquet libero adipiscing risus lobortis eleifend quis at velit. Duis at leo urna. Praesent facilisis faucibus neque, ut ullamcorper lacus gravida a. Donec vel iaculis sapien." width="90%" editable="false" visible="{data!=null?true:false}"/> <s:List id="list" width="659" creationComplete="list_creationCompleteHandler(event)" click="init()" labelField="questionDesc"> <s:AsyncListView list="{getSurveyQuestionsResult.lastResult}"/> </s:List> </s:View>

In my flex mobile project I have 2 views

is a list of surveys is a list of survey questions

Each survey has different questions to the object is select a survey from the list on view 1 and pass the record id onto view 2 to query the data based on the ID.

Where I am struggling is to take the survey ID and have it passed to the actionscript on page 2 from where I will retrieve the parameterised data.

All tips appreciated.

My Page 1 code

<?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:surveynameservice="services.surveynameservice.*" title="surveyMaster"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import spark.events.IndexChangeEvent; protected function list_creationCompleteHandler(event:FlexEvent):void { getAllSurveynameResult.token = surveynameService.getAllSurveyname(); } protected function surveySelected(event:IndexChangeEvent):void { // TODO Auto-generated method stub var tmpObj:Object = new Object(); tmpObj.sID = list.selectedItem.surveyID; tmpObj.sName = list.selectedItem.surveyName; (this.parentDocument as cp_dbHomeView).rightNav.activeView.data=tmpObj; } ]]> </fx:Script> <fx:Declarations> <s:CallResponder id="getAllSurveynameResult"/> <surveynameservice:SurveynameService id="surveynameService"/> <!-- Place non-visual elements (e.g., services, value objects) here --> </fx:Declarations> <s:List id="list" x="-1" y="0" width="171" height="100%" change="surveySelected(event)" creationComplete="list_creationCompleteHandler(event)" labelField="surveyName"> <s:AsyncListView list="{getAllSurveynameResult.lastResult}"/> </s:List> </s:View>

My Page 2 code

<?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:surveyquestionsservice="services.surveyquestionsservice.*" creationComplete="init()" title="{data.sID}"> <fx:Script> <![CDATA[ import mx.events.FlexEvent; import spark.components.DataRenderer; public function init():void{ } protected function list_creationCompleteHandler(event:FlexEvent):void { getSurveyQuestionsResult.token = surveyquestionsService.getSurveyQuestions(data); } ]]> </fx:Script> <s:layout> <s:VerticalLayout paddingTop="15" paddingBottom="15" paddingLeft="15" paddingRight="15" gap="5" horizontalAlign="center" verticalAlign="top"/> </s:layout> <fx:Declarations> <s:CallResponder id="getSurveyQuestionsResult"/> <surveyquestionsservice:SurveyquestionsService id="surveyquestionsService"/> </fx:Declarations> <s:Label text="Click on a location on the left to explore!" visible="{data==null?true:false}"/> <s:Label text="Information about {this.data.surveyID}" visible="{data!=null?true:false}"/> <s:TextArea text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur accumsan felis ac tortor aliquam iaculis. Phasellus hendrerit viverra enim, sit amet scelerisque lectus dictum at. Aenean sodales nisi sed leo congue et porttitor ligula vehicula. Pellentesque turpis massa, suscipit vel fermentum quis, dignissim sed ipsum. Nulla aliquet libero adipiscing risus lobortis eleifend quis at velit. Duis at leo urna. Praesent facilisis faucibus neque, ut ullamcorper lacus gravida a. Donec vel iaculis sapien." width="90%" editable="false" visible="{data!=null?true:false}"/> <s:List id="list" width="659" creationComplete="list_creationCompleteHandler(event)" click="init()" labelField="questionDesc"> <s:AsyncListView list="{getSurveyQuestionsResult.lastResult}"/> </s:List> </s:View>

最满意答案

好的,谢谢你澄清那部分,所以我的理解是MXML中的绑定工作正常,你根本不知道如何检索你传递给服务的第二次调用的参数? 如果是这样,您应该能够在PHP中使用$ _REQUEST或$ _POST或$ _GET,具体取决于您在服务上设置的HTTP方法(或默认情况下使用的任何方法,我相信它通常默认为AS3服务类的GET)。

如果您的问题只是您想知道数据何时进入并在该点进行调用,那么您只需要覆盖设置数据,如

override public function set data(value:Object):void { super.data = value; if(!data || data == value) return; getSurveyQuestionsResult.token = surveyquestionsService.getSurveyQuestions(data); }

Okay thanks for clarifying that part, so my understanding is that the bindings in the MXML are working fine and you simply don't know how to retrieve the parameters that you are passing to the second call on the service? If so you should be able to use $_REQUEST or $_POST or $_GET in PHP depending on which HTTP method you set on the service (or whatever it uses by default I believe it's usually GET by default for the AS3 service classes).

If instead your problem is just that you want to know when the data comes in and make the call at that point then you just need to override set data like

override public function set data(value:Object):void { super.data = value; if(!data || data == value) return; getSurveyQuestionsResult.token = surveyquestionsService.getSurveyQuestions(data); }

更多推荐

本文发布于:2023-08-04 10:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1413906.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   视图   数据   FLEX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!