问题
I am trying to filter xml data but right now I there are no data appearing in the list. Am I doing something wrongly? Sorry guys I am still new to this website too. Pardon me If I posted the wrong way.
This is the error.
TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@51443c1 to XMLList.
xmlns:s="library://ns.adobe.com/flex/spark" title="Malls"
creationComplete="malls.send()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:HTTPService id="malls" url="assets/details.xml"
result="malls_resultHandler(event)"/>
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var ml:XMLListCollection;
private function malls_resultHandler(Event:ResultEvent):void
{
ml = new XMLListCollection(malls.lastResult.list.mallD);
}
private function filterDemo():void{
ml.filterFunction=searchDemo;
ml.refresh();
}
private function searchDemo(item:Object):Boolean{
var isMatch:Boolean=false;
if(item.name.toLowerCase().search(search.text.toLowerCase())!=-1){
isMatch=true;
}
return isMatch;
}
]]>
</fx:Script>
<s:navigationContent/>
<s:titleContent>
<s:TextInput id="search" change="filterDemo()" x="10" y="10" prompt="Search"/>
</s:titleContent>
<s:List id="list" top="0" bottom="0" left="0" right="0"
dataProvider="{ml}"
change="navigator.pushView(MallsDetails, list.selectedItem)">
<s:itemRenderer>
<fx:Component>
<s:IconItemRenderer
label="{data.name}"/>
</fx:Component>
</s:itemRenderer>
</s:List>
回答1:
Try this,
We needn't mention XML root tag name here so just get rid of list
tag name when access XML.
Add resultFormat="e4x"
to HTTPService component.
<s:HTTPService id="malls" url="assets/details.xml" resultFormat="e4x"
result="malls_resultHandler(event)"/>
ml = new XMLListCollection(malls.lastResult.mallD);
To
var response:XML = malls.lastResult as XML;
var mallIDXMLList:XMLList = response.mallD;
m1 = new XMLListCollection(mallIDXMLList);
回答2:
You can try to replace
ml = new XMLListCollection(malls.lastResult.list.mallD);
by
var xmllist:XMLList = XMLList (malls.lastResult.list.mallD);
ml = new XMLListCollection(xmllist);
来源:https://stackoverflow.com/questions/21817375/data-filtering-for-xml-flex