首页 > flex, flex 控件用法 > HTTPService与xml结合绑定DataGrid

HTTPService与xml结合绑定DataGrid

1.定义HTTPService
   <mx:HTTPService id="employeeService"
  url="data/employees.xml"
  result="resultHandler(event)"
  fault="faultHandler(event)"/>
2.初始化发送HTTPService  initialize="employeeService.send()"

3.返回结果定义 private function resultHandler(event:ResultEvent):void {
    employeeData = event.result.employees.employee;//event.result+employees.employee结合5
   }
4.DataGrid绑定 dataProvider="{employeeData}
5.<?xml version="1.0"?>
<employees>
 <employee>
  <firstname>Renee</firstname>
  <lastname>Dieviss</lastname>
  <id>rdieviss</id>
  <title>President</title>
  <email>rdieviss@test.com</email>
  <managerid></managerid>
  <department>Corporate Team</department>
  <location>San Francisco</location>
  <phone>415-555-1212</phone>
  <directdial>33782</directdial>
  <desklocation>10-1</desklocation>
  <city>San Francisco</city>
  <state>California</state>
  <countrycode>US</countrycode>
  <postalcode>94103</postalcode>
 </employee>
</employees>

完整的mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
 layout="absolute"
 initialize="employeeService.send()">
 
 <!-- Code for Retrieving data via HTTPService (8:26) video
   http://link.brightcove.com/services/player/bcpid1681730258?bctid=1680571179 -->
  
 <!-- Run the application first and look at the returned data displayed in the DataGrid.
      Next, add a breakpoint inside the resultHandler() and debug the application to view the returned data in the

debugger. 
    Finally, generate a fault by changing the url in the HTTPService object so it is mispelled and
    then debug the application and look at the fault data. -->
   
 <mx:Script>
  <![CDATA[
   import mx.rpc.events.FaultEvent;
   import mx.collections.ArrayCollection;
   import mx.rpc.events.ResultEvent;
   
   // Variable to hold the results of the HTTPService call
   [Bindable]
   private var employeeData:ArrayCollection;
   
   // result event handler for employeeService HTTPService call
   private function resultHandler(event:ResultEvent):void {
    employeeData = event.result.employees.employee;
   }
   
   // fault event handler for employeeService HTTPService call
   private function faultHandler(event:FaultEvent):void {
    // Add code here for what to do when there is an error retrieving data
   }
   
  ]]>
 </mx:Script>
 
 <!-- HTTPService object defining where to get data from and what to do with it when it is returned.
   The actual call to the server is made when the Application is initialized; see the Application tag's
   initialize event. -->
 <mx:HTTPService id="employeeService"
  url="data/employees.xml"
  result="resultHandler(event)"
  fault="faultHandler(event)"/>
  
 <!-- DataGrid displaying all the data returned from the call to the server -->
 <mx:DataGrid dataProvider="{employeeData}"
  width="100%" height="100%" />
 
</mx:Application>

数据employees.xml

本文例子来源:一周学会flex里的FlexInAWeek_Day1_Projects\Video10_Retrieving_Data_via_HTTPService_Solution

原创文章转载请注明出处:云飞扬IT的blog

本文链接: http://www.ajaxcn.net/archives/96

一键分享到:新浪微博分享  分享到网易微博    转贴到开心网  推荐到豆瓣  分享到QQ空间    RSS订阅
  1. 2009年9月2日09:31 | #1

    以后学习flex就来你这里

    能再多谢谢关于flex与net sql通信的文章吗??

    比如,我在net里面建立dll文件,在flex里面是否可以引用,并调用里面的方法

    还是只能在net里面建立webservices,然后在flex里面引用?

    期待大幅,谢谢!

  2. 2009年9月2日21:26 | #2

    好像flex无法引用net的dll文件,除了HTTPService,还可以用webservices交互,目前我也循循渐渐的在学习中,以后学完会多搞些net与flex交互的,毕竟也是搞net的,不用谢!!欢迎你来到我的小站!!

  1. 本文目前尚无任何 trackbacks 和 pingbacks.

key office 2010

office 2010 key

corel dvd moviefactory 6

corel dvd moviefactory 6 downloads

serial corel draw 11

serial corel draw 11 serials

windows 7 key

windows 7 key

office 2010 professional key

office 2010 key

windows key

windows key

free winrar download for xp

download winrar for xp for free

winrar password cracker serial

wirar password cracker

cs5 serialz

cs5 serialz free

photoshop key

photoshop key

free corel photoshop download

free corel photoshop download keygen

photo shop key

photo shop key

download photo shop free

photo shop serial

serial winzip 11

serial winzip 11 key

adobe free

adobe free

windows 7 free

windows 7 crack

winrar 3 download

winrar 3 download freedownload

office 2010 free

office 2010 key

free corel downloads

free corel downloads cracked