1.ArrayCollection转成xml类型示例 下面模拟一组数据exams,将其转化为xml形式.详细代码见下:
import mx.collections.ArrayCollection;
[Bindable]private var shijxml:XML;
private function init():void{
shijxml = arrToXml(exams);
}
[Bindable]
public var exams: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"} ]);
private function arrToXml(arr:ArrayCollection):XML{
var root:XML = new XML("");
for(var i:int = 0;i var node:XML = new XML("");
node.sjtitle = arr[i].sjtitle;
node.kemu= arr[i].kemu;
node.shijID= arr[i].shijID;
node.num= arr[i].num;
root.appendChild(node);
}
return root;
}
private function closeHandler(event:Event):void {
show.text="试卷标题: "+ ComboBox(event.target).selectedItem;
var temp:String=String(ComboBox(event.target).selectedItem);
for each(var xml:XML in shijxml.node){
if(xml.sjtitle==temp){
show.text="考试科目: "+xml.kemu+"\n"+"试卷题数: "+xml.num+"\n"+
"试卷编号: "+xml.shijID;
}
}
}
]]>
import mx.collections.ArrayCollection;
[Bindable]private var shijxml:XML;
private function init():void{
shijxml = arrToXml(exams);
}
[Bindable]
public var exams: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"} ]);
private function arrToXml(arr:ArrayCollection):XML{
var root:XML = new XML("");
for(var i:int = 0;i var node:XML = new XML("");
node.sjtitle = arr[i].sjtitle;
node.kemu= arr[i].kemu;
node.shijID= arr[i].shijID;
node.num= arr[i].num;
root.appendChild(node);
}
return root;
}
private function closeHandler(event:Event):void {
show.text="试卷标题: "+ ComboBox(event.target).selectedItem;
var temp:String=String(ComboBox(event.target).selectedItem);
for each(var xml:XML in shijxml.node){
if(xml.sjtitle==temp){
show.text="考试科目: "+xml.kemu+"\n"+"试卷题数: "+xml.num+"\n"+
"试卷编号: "+xml.shijID;
}
}
}
]]>
参考文献:
1.Flex:ArrayCollection转xml形式的实例. http://xaajie.javaeye.com/blog/379054
阅读(2190) | 评论(0) | 转发(0) |