Flex:ArrayCollection轉xml形式的實例
系統
1862 0
ArrayCollection
轉成xml類型示例
下面模擬一組數據exams,將其轉化為xml形式.詳細代碼見下:
-
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
-
<
mx:Application
xmlns:mx
=
"http://www.adobe.com/2006/mxml"
layout
=
"absolute"
fontSize
=
"12"
creationComplete
=
"init()"
>
-
<
mx:Style
source
=
"style/Smoke.css"
/>
-
<
mx:Script
>
-
<![CDATA[
-
importmx.collections.
ArrayCollection
;
-
[Bindable]privatevarshijxml:XML;
-
-
privatefunctioninit():void{
-
shijxml=arrToXml(exams);
-
}
-
-
[Bindable]
-
publicvarexams:
ArrayCollection
=new
ArrayCollection
(
-
[{sjtitle:"數據結構第一章",kemu:"數據結構",shijID:"sj000",num:"30"},
-
{sjtitle:"數據結構第二章",kemu:"數據結構",shijID:"sj001",num:"30"},
-
{sjtitle:"組成原理第一章",kemu:"組成原理",shijID:"zc000",num:"50"},
-
{sjtitle:"組成原理第二章",kemu:"組成原理",shijID:"zc001",num:"30"}]);
-
-
privatefunctionarrToXml(arr:
ArrayCollection
):XML{
-
varroot:XML=newXML("<root/>");
-
for(vari:int=0;i<arr.length;i++){
-
varnode:XML=newXML("<node/>");
-
node.sjtitle=arr[i].sjtitle;
-
node.kemu=arr[i].kemu;
-
node.shijID=arr[i].shijID;
-
node.num=arr[i].num;
-
root.appendChild(node);
-
}
-
returnroot;
-
}
-
privatefunctioncloseHandler(event:Event):void{
-
show.text="試卷標題:"+ComboBox(event.target).selectedItem;
-
vartemp:String=String(ComboBox(event.target).selectedItem);
-
foreach(varxml:XMLinshijxml.node){
-
if(xml.sjtitle==temp){
-
show.text="考試科目:"+xml.kemu+"/n"+"試卷題數:"+xml.num+"/n"+
-
"試卷編號:"+xml.shijID;
-
}
-
}
-
}
-
]]>
-
</
mx:Script
>
-
<
mx:Panel
width
=
"100%"
height
=
"100%"
layout
=
"absolute"
>
-
<
mx:DataGrid
height
=
"100%"
width
=
"50%"
dataProvider
=
"{exams}"
>
-
</
mx:DataGrid
>
-
<
mx:ComboBox
y
=
"79"
close
=
"closeHandler(event);"
dataProvider
=
"{shijxml.node.sjtitle}"
right
=
"88"
>
</
mx:ComboBox
>
-
<
mx:Text
y
=
"111"
id
=
"show"
width
=
"185"
height
=
"126"
right
=
"50"
/>
-
</
mx:Panel
>
-
</
mx:Application
>
Flex:ArrayCollection轉xml形式的實例
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元