2011-05-06 12 views

回答

0

首先提取XMLList從您的XML需要的節點。然後使用ArrayUtil.toArray()方式如下:

var myCollection:ArrayCollection = new ArrayCollection(ArrayUtil.toArray(myXMLList)); 
0
<!-- 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> 
相關問題