繁体   English   中英

如何在Flex的数组集合中添加XML文件?

[英]How to Add XML File in Array collection in Flex?

我在flex。中创建了一个数组集合,并且我有一个XML文件。 现在我想将该XML文件调用为arraycollection,所以请给我有关的想法。 我该如何实现???

提前致谢 - -

首先从您的XML中提取带有所需节点的XMLList 然后通过以下方式使用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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM