加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

webservice传来的结果 并放入DataGrid中

发布时间:2020-12-17 02:55:17 所属栏目:安全 来源:网络整理
导读:?xml version="1.0" encoding="utf-8"? mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" ?mx:Panel ????? mx:VBox ??????? mx:HBox ????????? mx:Label text="username" / ????????? mx:TextInput id="nam" / ??????? /mx:HBox ??????? mx:H

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
?<mx:Panel>
????? <mx:VBox>
??????? <mx:HBox>
????????? <mx:Label text="username" />
????????? <mx:TextInput id="nam" />
??????? </mx:HBox>
??????? <mx:HBox>
????????? <mx:Label text="password" width="61" />
????????? <mx:TextInput password="true" id="pwd" />
??????? </mx:HBox>
??????? <mx:Button label="login" click="articlesys.adminlogin.send()" />
????? </mx:VBox>
?</mx:Panel>
?<mx:Button label="invoke" width="203" click="articlesys.getBoards.send()"/>
?<mx:DataGrid id="dg1" dataProvider="getRsArray()" cellPress="dgCellClick(event)"><!-- dgCellClick 中的event接收 DataGrid发送的cellPress事件消息 -->
??? </mx:DataGrid>
?<mx:TextArea id="ta" width="296" height="129" text="{articlesys.adminlogin.result}" />
?<mx:WebService serviceName="articlesys" id="articlesys"><!-- 只要在flex-config.xml文件里面配置一个named的webservices就可以在这里用指定的名字直接使用 -->
????? <mx:operation name="adminlogin">
??????? <mx:request>
????????? <password>{pwd.text}</password>
????????? <username>{nam.text}</username>
??????? </mx:request>
????? </mx:operation>
????? <mx:operation name="getBoards" result="rstogrid()">
??????? <mx:request>
????????? {ta.text}
??????? </mx:request>
????? </mx:operation>
??? </mx:WebService>
<mx:Script>
<![CDATA[
var rsStr:String;

//rstogrid是处理从webservice接受的字符串, 把它处理成数组以供DataGrid使用

?function rstogrid(){? var rs_array:Array = new Array();? rsStr = articlesys.getBoards.result;? var doc_xml:XML=new XML();? doc_xml.parseXML(rsStr);? ? var out_str:String = new String();? var xnod_node:XMLNode=doc_xml.firstChild;//将第一个节点附值给XMLNode对象? //var xchild_node:XMLNode=xnod_node.firstChild;? var row_obj;? var i,j;? for(j=0;xnod_node != null;j++){?? //xchild_node = xnod_node.firstChild;?? row_obj = new Object();//每次 new 一下就不会出现重复的结果,不然这个数组老是指向同一个内存地址?? for (i =(xnod_node.childNodes.length-1); i>=0; i--) {//由于节点不是textNode所以需要以下面这种方式调用他的值??? row_obj[xnod_node.childNodes[i].nodeName]=xnod_node.childNodes[i].firstChild.nodeValue;//直接给Object型数组的元素取名,这里是给元素取名不是给Object对象??? //row_obj[i]=xnod_node.childNodes[i].firstChild.nodeValue;//这种方法得到的元素名就只是数字?? }?? rs_array.push(row_obj);//将对象压入另一个数组,形成DataGrid可以使用的二维数组?? xnod_node = xnod_node.nextSibling;? }? dg1.dataProvider = rs_array;? ? //dg1.dataProvider = articlesys.getBoards.result;? ta.text = rsStr;?}??function dgCellClick(event){? /*? - itemIndex Index of the selected item.? - columnIndex Index of the selected column.? - view Currently selected Object.? - target Reference to the component that triggered the event. ? - type Name of the event. ? */? ta.text = event.itemIndex;?}]]></mx:Script></mx:Application>?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读