问题描述
我的 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:
var s:String = event.result as String;
var xml:XML = 新的 XML(s);
testList = xml.user;
数据在一个函数中使用,然后它也传递给我的一个组件,我尝试在列表中显示 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.您可以使用实现 IList
的 XMLListCollection
来包装结果,以便您可以将其用作数据提供程序.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!