本文介绍了Adobe Flex:无法将XMLList转换为mx.collections.IList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Flex应用程序运行到php页面的服务,该页面从我的数据库中提取数据,然后以XML格式构造结果.我在任何函数之外创建了一个名为testList的新XMLList,然后返回结果时(它们首先作为包含所有XML代码的单个字符串伸缩),我将使用以下代码将其转换为XML,然后追加到我的testList:

My Flex app runs a service to a php page that pulls data from my database, then structures the result in an XML format. I created a new XMLList called testList outside of any functions, then when the results come back (they first come to flex as a single string holding all of the XML code) I have the following code to turn it into XML and then append to my testList:

数据在一个函数中使用,然后也传递给我的一个组件,在该组件中,我尝试在列表中显示XMLList(将testList作为dataProvider),并且出现以下错误:

The data is used in one function, then it's also passed to a component of mine, where I try to display the XMLList in a List (with testList as dataProvider) and I get the following error:

TypeError:错误#1034:类型强制失败:无法将XMLList @ 68ffa01转换为mx.collections.IList.

TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@68ffa01 to mx.collections.IList.

我感觉这可能是一个菜鸟错误,但是可以提供任何帮助.

I have a feeling it's probably a noob error, but any help is appreciated.

推荐答案

E4X表达式返回匹配XML的列表. xml.user为您提供所有user元素的XMLList.您可以使用实现了IListXMLListCollection来包装结果,以便将其用作数据提供者.

E4X expressions return lists of matching XML. xml.user gives you an XMLList of all user elements. You can use XMLListCollection, which implements IList, to wrap the result so you can use it as a dataprovider.

var xml:XML = new XML(event.result as String);
var list:IList = new XMLListCollection(xml.user);

另一个选择是循环遍历XMLList并将其添加到数组或所需的任何集合中.如果您确定只有一个用户,则可以执行以下操作:

The other option is to loop though the XMLList and add it to an array or whatever collection you need. If you know for sure that there is only one user, you can do this instead:

var user:XML = xml.user[0];

这篇关于Adobe Flex:无法将XMLList转换为mx.collections.IList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 05:08