30

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

Flex中操作XML(下)

系統 1849 0

?

四 在Flex中使用XML的例子

大的XML文檔用來顯示數據或者顯示列表的情況比較多,比如顯示數據時作為Datagrid的數據源,或者為List,Combobox,Tree等的顯示列表。

?

當我們使用List或者Combobox的時候,往往會把XML對象轉換為ArrayCollection對象,看下面的例子

外部Xml文件

view plaincopy to clipboardprint?
<books>?????????????????????
??? <book name="flex tutorial">?????????????????
??????? <price>30</price>?????????????
??????? <author>adobe</author>????????????
??? </book>?????????????????
??? <book name="air tutorial">??????????????????
??????? <price>40</price>?????????????
??????? <author>adobe</author>????????????
??? </book>?????????????????
??? <book name="java tutorial">?????????????????
??????? <price>50</price>?????????????
??????? <author>sun</author>??????????????
??? </book>?????????????????
</books>???????????????????
<books>?????
<book name="flex tutorial">????
?? <price>30</price>???
?? <author>adobe</author>???
</book>????
<book name="air tutorial">????
?? <price>40</price>???
?? <author>adobe</author>???
</book>????
<book name="java tutorial">????
?? <price>50</price>???
?? <author>sun</author>???
</book>????
</books>

Flex文件

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>??????????????????
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"??????????????????
layout="absolute"????????????????
creationComplete="init()">????????????????
<mx:Script>???????????????
<!--[CDATA[??????????????????
????? import mx.collections.ArrayCollection;??????????????????
????? import mx.rpc.events.ResultEvent;???????????????
????? //用于數據綁定的ArrayCollection????????????????
????? [Bindable]private var externalData:ArrayCollection = new ArrayCollection();?????????????????
??????????????????????
????? private function init():void {??????????????????
????????? //發送請求??????????????????
????????? myService.send();???????????????
????? }???????????????
??????????????????????????
????? private function resultHandler(event:ResultEvent):void {????????????????
????????? //取得Xml對象中book節點的集合?????????????????
????????? externalData = event.result.books.book;?????????????????
????? }//斷點處??????????????????
]]-->????????????????
</mx:Script>??????????????????
<!--創建Httpservice對象加載外部Xml-->?????????????????
<mx:HTTPService id="myService"???????????????
????? url="xmlFile.xml"???????????????
????? result="resultHandler(event)"/>??????????????????
<!--用于顯示的list-->??????????????????
<mx:List id="datalist" dataProvider="{externalData}" labelField="name"/>??????????????????????????
</mx:Application>??????????????
<?xml version="1.0" encoding="utf-8"?>????
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"????
layout="absolute"????
creationComplete="init()">????
<mx:Script>????
<!--[CDATA[????
????? import mx.collections.ArrayCollection;????
????? import mx.rpc.events.ResultEvent;????
????? //用于數據綁定的ArrayCollection????
????? [Bindable]private var externalData:ArrayCollection = new ArrayCollection(); ????
???? ????
????? private function init():void {????
????????? //發送請求????
????????? myService.send();????
????? }????
???????? ????
????? private function resultHandler(event:ResultEvent):void {????
????????? //取得Xml對象中book節點的集合????
????????? externalData = event.result.books.book;????
????? }//斷點處????
]]-->????
</mx:Script>????
<!--創建Httpservice對象加載外部Xml-->????
<mx:HTTPService id="myService"????
????? url="xmlFile.xml"????
????? result="resultHandler(event)"/>????
<!--用于顯示的list-->????
<mx:List id="datalist" dataProvider="{externalData}" labelField="name"/>???????? ????
</mx:Application>

將上面的代碼以debug模式執行,程序停在斷點處,在variables視圖中我們可以很清晰的看到程序HttpService對象在加載外部 XML后已經把它轉換成了ArrayCollection對象,如下圖。這樣就可以很輕松的將數據源綁定到顯示列表對象List中。

Flex中操作XML(下)

?

?

另外一種情況,當我們使用Tree組件的時候,需要在HTTPService對象中加上resultFormat="e4x"以XML的格式讀取進來而不要轉換為ArrayCollection。

外部XML文件

view plaincopy to clipboardprint?
<books>?????
<category name="RIA">???
??? <book name="flex tutorial" price="30" author="adobe">??
??? </book>?????
??? <book name="air tutorial" price="40" author="adobe">????
??? </book>?????
</category>?????????
<category name="Java">??????????
??? <book name="java tutorial" price="50" author="sun">?????
??? </book>?????
</category>?????????
</books>???????
<books>
<category name="RIA">
<book name="flex tutorial" price="30" author="adobe">
</book>
<book name="air tutorial" price="40" author="adobe">
</book>
</category>??
<category name="Java">??
<book name="java tutorial" price="50" author="sun">
</book>
</category>??
</books>

Flex文件

view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>??????????????
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"??????????????
layout="absolute"????????????
creationComplete="myService.send()">??????????????
<mx:HTTPService id="myService"???????????
??? url="xmlFile.xml"?????????
??? resultFormat="e4x"/>???????
??????????????
<mx:XMLListCollection id="booktreesrc"?????????????
??? source="{myService.lastResult.category}"/>?????????
??????????????
<mx:Tree id="bookTree"?????????????
??? height="100%"?????????
??? dataProvider="{booktreesrc}"??????????
??? labelField="@name"/>???????
??????????????????????
</mx:Application>??????????
<?xml version="1.0" encoding="utf-8"?>???
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"???
layout="absolute"???
creationComplete="myService.send()">???
<mx:HTTPService id="myService"???
url="xmlFile.xml"??
resultFormat="e4x"/>??
???
<mx:XMLListCollection id="booktreesrc"???
source="{myService.lastResult.category}"/>??
???
<mx:Tree id="bookTree"???
height="100%"??
dataProvider="{booktreesrc}"??
labelField="@name"/>??
??????? ???
</mx:Application>

畫面顯示

Flex中操作XML(下)

Flex中操作XML(下)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 97色97色97色成人 | cao美女视频网站在线观看 | 亚洲午夜久久久久国产 | 久久亚洲精品专区蓝色区 | 天天操天天操天天干 | 成人亚洲视频 | 97精品国产高清久久久久蜜芽 | 在线观看国产一区二三区 | 国产欧美精品专区一区二区 | 99精品视频在线观看免费播放 | 亚洲精品一区henhen色 | 欧美v在线 | 亚洲日产 | 精品国产一区二区三区久 | 91视频亚洲| 九一视频在线 | 一级毛片a女人刺激视频免费 | 手机看片一区 | 四虎精品永久免费 | 五月开心六月伊人色婷婷 | 九月婷婷天天澡天天添天天爽 | 欧美人猛交日本人xxx | 夜夜艹日日艹 | 热久久网站 | 综合网在线视频 | 在线播放免费一级毛片欧美 | 日韩免费在线视频观看 | 日韩亚州| 中文字幕亚洲综久久2021 | 99久久精品免费观看区一 | 91精品国产免费自在线观看 | 久久久久久久国产精品 | 亚洲成在人线久久综合 | 久久国产精品久久久久久久久久 | 国产久视频观看 | 久久乐国产精品亚洲综合m3u8 | 毛片黄片视频 | 精品一本久久中文字幕 | 91色国产在线 | 手机看片欧美日韩 | 岛国精品在线 |