2

当我检索只有 1 个节点(无重复节点)的 XML 并尝试存储在 ArrayCollection 中时,我收到此错误。- 当我有超过 1 个“名称”节点时......我没有收到错误。

TypeError: Error #1034: Type Coercion failed: cannot convert "XXXXXX" to mx.collections.ArrayCollection.

此错误作为代码行发生:

myList= e.result.list.name;

为什么 ArrayCollection 不能与单个节点一起使用?我正在使用这个 ArrayCollection 作为组件的数据提供者 - 有没有我可以使用的替代方案,它既可以使用单个节点,也可以使用重复节点,也可以作为数据提供者工作?提前致谢!

代码:

[Bindable]
private var myList:ArrayCollection= new ArrayCollection();

        private function getList(e:Event):void{

            var getStudyLoungesService:HTTPService = new HTTPService();
            getStuffService.url = "website.com/asdf.php";
            getStuffService.addEventListener(ResultEvent.RESULT, onGetList);
            getStuffService.send();

        }

        private function onGetList(e:ResultEvent):void{

            myList= e.result.list.name;
        }
4

2 回答 2

1

resultFormat应设置e4x为:

var getStudyLoungesService:HTTPService = new HTTPService();
getStuffService.url = "website.com/asdf.php";
getStuffService.resultFormat = "e4x";
getStuffService.addEventListener(ResultEvent.RESULT, onGetList);
getStuffService.send();

然后,您可以按如下方式检索结果:

new XMLListCollection(e.result.list.name);

(所有功劳都归功于 Amarghosh,几个小时以来一直在敲我的脑袋,但几乎错过了他的评论!)

于 2011-04-26T21:54:14.720 回答
0

您不能直接将 anXML甚至 an分配给XMLListtype 的变量ArrayCollection。使用 anXMLListCollection并将数据传递给它的构造函数。

[Bindable]
private var myList:XMLListCollection;

myList = new XMLListCollection(e.result.list.name);
于 2010-04-29T09:13:32.860 回答