我有一个XML文件,我住在applicationStorageDirectory中,我需要将内容加载到ArrayCollection中。
XML看起来像这样(见下文),我可以对它进行读写,但我需要将数据放在ArrayCollection中,这样我才能将其加载到datagrid中。
<?xml version="1.0" encoding="utf-8"?>
<item>
<sort>2012/10/31PM0000</sort>
<date>Wed Oct 31 2012</date>
<event>Halloween</event>
<time>12:00 PM</time>
</item>
<item>
<sort>2012/09/13AM0000</sort>
<date>Thu Sep 13 2012</date>
<event>Enter Details</event>
<time>12:00 AM</time>
</item>我发现我可以在HTTP服务中使用url=“app -storage:/Remerder.xml”,它是否能与Air一起使用,还有待观察。
<s:HTTPService id="reminderXML" url="app-storage:/reminder.xml" result="reminderDataHandler(event)" fault="faultHandler(event);"/>发布于 2012-09-14 12:08:10
您可以尝试使用下面的util,它会将您的XML/XMLList转换为ICollectionView。您可以使用它来绑定到datagrid。
public static function toCollection( value:Object ):ICollectionView
{
var collection:ICollectionView;
collection = null;
if (value is Array)
{
collection = new ArrayCollection(value as Array);
}
else if (value is ICollectionView)
{
collection = ICollectionView(value);
}
else if (value is IList)
{
collection = new ListCollectionView(IList(value));
}
else if (value is XMLList)
{
collection = new XMLListCollection(value as XMLList);
}
else if (value is XML)
{
var xl:XMLList = new XMLList();
xl += value;
collection = new XMLListCollection(xl);
}
else
{
// convert it to an array containing this one item
var tmp:Array = [];
if (value != null)
tmp.push(value);
collection = new ArrayCollection(tmp);
}
return collection;
}https://stackoverflow.com/questions/12417878
复制相似问题