flex中怎么把后台的值赋给前台页面上的text标签上

 我来答
这名字长
2014-12-22 · 超过23用户采纳过TA的回答
知道答主
回答量:81
采纳率:0%
帮助的人:37.6万
展开全部
后台返回值是string类型
后台返回值是一个类
后台返回值是一个数组
前面的话,flex端与后台交互的代码:
如,我的后台java中有一个ZhpfxService类,现在要在前台flex中调用,则:
在flex中得到java后台数据,得要注意几步
1.在文件中先要包含映射过来的server类,如下代码
xmlns:zhpfx="com.zhpf.services.*"
2.在<fx:Declarations>中进行声明,如下代码
<fx:Declarations>
<zhpfx:ZhpfxService id="zhpfx" fault="faultHandler(event)" showBusyCursor="true"/>
<s:CallResponder id="getValidNameToken" result="getValidNameToken_resultHandler(event)" fault="faultHandler(event)"/>
</fx:Declarations>
3.然后调用这个类的相应方法,如下代码
getValidNameToken.token = zhpfx.getValidName(); //调用后台类的getValidName()方法
4.最后出来结果的函数,
这个是调用成功的出来方法,
protected function getValidNameToken_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var ac:ArrayCollection = event.result as ArrayCollection;
var arr:Array = ac.toArray();
var str:String = "";
for(var a in arr){
str += arr[a].s0+" "+arr[a].s1;
}
Alert.show(str);
}

/**这个是失败提醒*/
protected function faultHandler(event:FaultEvent):void{
AlertUtil.AlertShow("本次操作失败,请重新再试或查看网络是否正常","信息提醒",Alert.OK, this,null,3);
}
下面正是进入正题:
返回值的几种情况,分别如何处理:
后台返回值是string类型
protected function getValidNameToken_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
Alert.show((String)(event.result as Object));
}
后台返回值是一个类
protected function getValidNameToken_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var m:Object: = event.result as Object;
Alert.show(m.s1); //这里m对象有个属性是s1,属性名必须相同。
}
后台返回值是一个数组
protected function getValidNameToken_resultHandler(event:ResultEvent):void
{
// TODO Auto-generated method stub
var ac:ArrayCollection = event.result as ArrayCollection;
var arr:Array = ac.toArray();
var str:String = "";
for(var a in arr){
str += arr[a].s0+" "+arr[a].s1; //属性名必须相同
}
Alert.show(str);
}

满意请采纳 谢谢
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
波谷很忙
2014-12-22 · TA获得超过1.3万个赞
知道大有可为答主
回答量:2540
采纳率:88%
帮助的人:1496万
展开全部
先写一个addmemberVO.aspackage vo
{
[Bindable]
public class memberVO
{
public var id:int;

public var firstname:String;
public var surname:String;
public var birth:String;
public var gender:String;
public var address:String;
//
public var email:String;
public var password:String;
public var mobilenumber:String;
public var profession:String;
public var employer:String;
public var nominatedby:String;

public var describe:String;
public var perfect:String;
public var favourite:String;
public var photo:String;
public var seq:String;

public var addtime:String;

public var status:String;

public var que4:String;

//使用数据填充对象
public function fill(obj:Object):void{

for(var i:* in obj){
this[i] = obj[i];
}
}
}
} 2.然后在addmember.mxml上写: 这个是添加的方法:public function addButtonMember():void
{

var addMemberData:memberVO=new memberVO();
if(nopic.source!="icons/nopic.png"){
addMemberData.firstname=firstname.text;
addMemberData.surname=surname.text;
addMemberData.birth=birth.text;
addMemberData.gender=radioGroup.selectedValue.toString();
addMemberData.address=address.text;

addMemberData.email=email.text;
addMemberData.password=password.text;
addMemberData.mobilenumber=mobilenumber.text;
addMemberData.profession=profession.text;
addMemberData.employer=employer.text;
addMemberData.nominatedby=nominatedby.text;

addMemberData.status=status.selectedItem.label;

addMemberData.describe=describe.text;
addMemberData.perfect=perfect.text;
addMemberData.favourite=favourite.text;
addMemberData.photo=this.photoSrc;

addMemberData.que4=que4.text;

dbConn.addMemberInfo(addMemberData);

}else if(nopic.source=="icons/nopic.png"){
Alert.show("please write photoSrc!");
}

} 页面的布局:<mx:Array id="arr">
<mx:Object label="Male" data="Male" />
<mx:Object label="Female" data="Female" />

</mx:Array> <mx:Button x="71" y="554" buttonMode="true" useHandCursor="true" styleName="themeButton" icon="@Embed(source='/icons/new_item2.png')" toolTip="New item" click="addButtonMember()" />
<mx:Label x="89" y="33" text="FIRST NAME:"/>
<mx:Label x="102" y="62" text="SURNAME:"/>
<mx:Label x="74" y="88" text="DATE OF BIRTH:"/>
<mx:TextInput x="198" y="32" height="18" width="293" id="firstname"/>
<mx:TextInput x="198" y="58" height="18" width="293" id="surname"/>
<mx:TextInput x="198" y="84" height="18" width="293" id="birth"/>
<mx:HBox id="hb" x="198" y="110" >
<mx:RadioButtonGroup id="radioGroup" />
<mx:Repeater id="radioRepeater"
dataProvider="{arr}">
<mx:RadioButton id="radioButtons"
label="{radioRepeater.currentItem.label}"
selected="true"
group="{radioGroup}"
/>
</mx:Repeater>
</mx:HBox>
<mx:TextInput x="198" y="136" height="18" width="293" id="address"/>
<mx:TextInput x="198" y="170" height="18" width="293" id="email"/>
<mx:TextInput x="198" y="197" height="18" width="293" id="password"/>
<mx:TextInput x="198" y="224" height="18" width="293" id="mobilenumber"/>
<mx:TextInput x="198" y="254" height="18" width="293" id="profession"/>
<mx:TextInput x="198" y="280" height="18" width="293" id="employer"/>
<mx:TextInput x="198" y="306" height="18" width="293" id="nominatedby"/>
<mx:ComboBox id="status" x="198" y="332" dataProvider="{ModelLocator.statusArr}"></mx:ComboBox>
<mx:Label x="111" y="111" text="GENDER:"/>
<mx:Label x="107" y="137" text="ADDRESS:"/>
<mx:Label x="121" y="171" text="EMAIL:"/>
<mx:Label x="95" y="198" text="PASSWORD:"/>
<mx:Label x="63" y="225" text="MOBILE NUMBER:"/>
<mx:Label x="87" y="255" text="PROFESSION:"/>
<mx:Label x="95" y="281" text="EMPLOYER:"/>
<mx:Label x="71" y="308" text="NOMINATED BY:"/>
<mx:Label x="71" y="354" text="How would your friends describe you?" width="284"/>

<mx:TextInput x="71" y="372" width="749" height="26" id="describe"/>
<mx:TextInput x="71" y="421" width="749" height="26" id="perfect"/>
<mx:TextInput x="71" y="469" width="749" height="26" id="favourite"/>
<mx:TextInput x="71" y="520" width="749" height="26" id="que4"/>
<mx:Label x="71" y="402" text="Brlefly tell us about your perfect night out." width="284"/>
<mx:Label x="71" y="449" text="What is your favourite club in London and why?" width="284"/>
<mx:Label x="71" y="503" text="Where did you heard about us?" width="284"/>
<mx:Button x="774" y="554" buttonMode="true" useHandCursor="true" styleName="themeButton" toolTip="Close" icon="@Embed(source='/icons/close2.png')" click="closeWindow()"/>
<mx:Image id="nopic" x="566" y="32" width="122" height="81" toolTip="Click to upload" click="upload()" source="icons/nopic.png"/>
<mx:ProgressBar id="bar" labelPlacement="center" themeColor="#F20D7A"
minimum="0" visible="true" maximum="100" label="Please select a file"
direction="right" mode="manual" width="122" y="34" x="566" height="81" />

<mx:Label x="123" y="334" text="Status:"/> 这样后台就可以一次性的接收到页面传来的参数!
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式