flex 遍历服务器端传过来的标准xml字符串
发布网友
发布时间:2024-09-26 08:14
我来回答
共3个回答
热心网友
时间:2024-10-04 20:20
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:HTTPService id="request4QueryNodes"
url="http://localhost/test/test.do"
showBusyCursor="true"
result="initNodes();"/>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.collections.ArrayCollection;
private function initNodes():void
{
var data4nodeAC:ArrayCollection=request4QueryNodes.lastResult.items.item as ArrayCollection;
if (data4nodeAC == null)
{
data4nodeAC=new ArrayCollection();
data4nodeAC.addItem(request4QueryNodes.lastResult.items.item);
}
var nodeInLayer1AC:ArrayCollection=new ArrayCollection();
var nodeInLayer2AC:ArrayCollection=new ArrayCollection();
var nodeInLayer3AC:ArrayCollection=new ArrayCollection();
for each (var node:Object in data4nodeAC)
{
if (node.LOCLAYER == 1)
nodeInLayer1AC.addItem(node);
else if (node.LOCLAYER == 2 || node.LOCLAYER == 3)
nodeInLayer2AC.addItem(node);
else if (node.LOCLAYER == 4 || node.LOCLAYER == 5)
nodeInLayer3AC.addItem(node);
}
var message:String='there are ' + nodeInLayer1AC.length + 'in Layer1\n';
message+='there are ' + nodeInLayer2AC.length + 'in Layer2\n';
message+='there are ' + nodeInLayer3AC.length + 'in Layer3\n';
Alert.show(message);
}
// 这里不是当作真正的数据源,而是告诉你后台传来的xml应该是什么格式,并且你在前台可以用这个数据源来测试遍历
private var xmlData:XML = <items>
<item>
<ID>1</ID>
<NAME>Node1</NAME>
<LOCLAYER>1</LOCLAYER>
</item>
<item>
<ID>2</ID>
<NAME>Node2</NAME>
<LOCLAYER>2</LOCLAYER>
</item>
<item>
<ID>3</ID>
<NAME>Node3</NAME>
<LOCLAYER>3</LOCLAYER>
</item>
<item>
<ID>4</ID>
<NAME>Node4</NAME>
<LOCLAYER>4</LOCLAYER>
</item>
<item>
<ID>5</ID>
<NAME>Node5</NAME>
<LOCLAYER>5</LOCLAYER>
</item>
</items>;
]]>
</mx:Script>
<mx:Button label="Send"
click="request4QueryNodes.send();"/>
</mx:Application>
热心网友
时间:2024-10-04 20:23
服务器可以是Arraylist,List,Map都可以啊
到flex就变成了ArrayCollection了
热心网友
时间:2024-10-04 20:23
var xml:XML = XML(string); 就可以了!
你想要什么样的?
--------------------------------------------------------------那要看你用什么方式通讯!