0
我已經在flex中創建了一個數組集合,並且我有一個XML文件。 現在我想將該XML文件調用到arraycollection中,所以請給我關於相同的想法。 我該如何做到這一點?如何在Flex中的Array集合中添加XML文件?
在此先感謝---
我已經在flex中創建了一個數組集合,並且我有一個XML文件。 現在我想將該XML文件調用到arraycollection中,所以請給我關於相同的想法。 我該如何做到這一點?如何在Flex中的Array集合中添加XML文件?
在此先感謝---
首先提取XMLList
從您的XML需要的節點。然後使用ArrayUtil.toArray()
方式如下:
var myCollection:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(myXMLList));
<!-- Application -->
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="creationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var arrColl:ArrayCollection;
protected function creationCompleteHandler(event:FlexEvent):void
{
arrColl = new ArrayCollection(books.book);
}
]]>
</fx:Script>
<fx:Declarations>
<fx:Model id="books" source="books.xml"/>
</fx:Declarations>
<!-- books.xml -->
<?xml version="1.0"?>
<books>
<book>
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
</book>
<book>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
</book>
<books>