Flex:ArrayCollection转xml形式的实例
系统
1693 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元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。
【本文对您有帮助就好】元