在我的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>
答案 0 :(得分:0)
好的,谢谢你澄清那个部分,所以我的理解是MXML中的绑定工作正常,你根本不知道如何检索你传递给服务第二次调用的参数?如果是这样,您应该能够在PHP中使用$ _REQUEST或$ _POST或$ _GET,具体取决于您在服务上设置的HTTP方法(或默认情况下使用的任何方法,我相信它通常默认为AS3服务类的GET)。 / p>
如果您的问题只是您想知道数据何时进入并在该点进行调用,那么您只需要覆盖设置数据,如
override public function set data(value:Object):void
{
super.data = value;
if(!data || data == value)
return;
getSurveyQuestionsResult.token = surveyquestionsService.getSurveyQuestions(data);
}
答案 1 :(得分:0)
我偶然发现了一个方法,将一个以上的参数传递给pushView方法调用的另一个视图。我在这个问题中发现的是,我可以传递一个Object类型的参数,并根据需要为这个参数创建尽可能多的自定义属性。
例如,我需要传递一个字符串和一个数组,我确实喜欢这个:
在来电者视图中:
var viewParameters:Object = new Object();
viewParameters.stringParam = myString;
viewParameters.listParam = myList;
navigator.pushView(CalledView, viewParameters);
并在被叫视图中:
var myString:String = data.stringParam;
var myList:Array = data.listParam as Array;
这里不需要覆盖设置数据函数,因为我正在调用已经填充数据的pushView。