資料來源為網路上的XML檔案,我們使用DropList裡面的dataProvider屬性為其綁定。
步驟一 : 在Declarations中宣告我們的HttpService並且指定服務的id以及服務位址
<fx:Declarations> <s:HTTPService id="employeeService" url="http://adobetes.com/f45iaw100/remoteData/employees.xml" /> </fx:Declarations> |
步驟二 : 使用該服務的send()方法得到HTTP響應,注意必須在creationComplete
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="850" creationComplete="employeeService.send()" > |
步驟三 : 綁定資料到DropList,注意,因為回傳資料型態有名稱、電話等等..所以要指定它的欄位為lastName。
<s:DropDownList id="dropDownList" dataProvider="{employeeService.lastResult.employees.employee}" labelField="lastName" /> |
完成!! 運行瀏覽器看看結果吧
關於這篇所用到的類別額外學習
<s:HTTPService>
You use the
<mx:HTTPService>
tag to represent an HTTPService object in an MXML file. When you call the HTTPService object's send()
method, it makes an HTTP request to the specified URL, and an HTTP response is returned. Optionally, you can pass parameters to the specified URL. When you do not go through the server-based proxy service, you can use only HTTP GET or POST methods. However, when you set the useProxy property to true and you use the server-based proxy service, you can also use the HTTP HEAD, OPTIONS, TRACE, and DELETE methods.mx.core.UIComponent.creationComplete
Dispatched when the component has finished its construction, property processing, measuring, layout, and drawing.
(意思就是當這個元件完成了它初始化的工作,並且可以顯示到畫面上)
(意思就是當這個元件完成了它初始化的工作,並且可以顯示到畫面上)
沒有留言:
張貼留言