来自php的XML填充Flex Combox



我很难从XML响应中填充组合。这是我收到的XML:

    <distros>
      <entry>
        <distro>CentOS</distro>
        <distro>Debian</distro>
        <distro>Other</distro>
        <distro>Sabayon</distro>
        <distro>Ubuntu</distro>
        <distro>VMware</distro>
        <distro>Windows</distro>
      </entry>
    </distros>

这可能是有史以来最基本的形式!

这是Flex代码:

private function getDistros():void
{
httpReq = new HTTPService;
httpReq.url = 'http://myserver/xml.php';
httpReq.resultFormat = 'e4x';
httpReq.method = 'GET';
httpReq.addEventListener(ResultEvent.RESULT, popDistros);
httpReq.send( null ); 
}
private function popDistros(event:ResultEvent):void
{
if(event.result != "")
{
    // Set the data to the XMLListCollection for lookup
    myXmlCollection= new XMLListCollection(event.result.entry);
    // Bind the ListCollection to the comboBox
    Alert.show(myXmlCollection.toString());
    distroCombo.dataProvider = myXmlCollection.toString();
}
}

和mxml:

                <mx:ControlBar x="139" y="10" width="266" height="358" verticalAlign="top" horizontalAlign="left" direction="vertical">
                    <mx:ComboBox id="distroCombo" labelField="distro"></mx:ComboBox>
                    <mx:ComboBox id="imageCombo"></mx:ComboBox>
                    <mx:Button label="Download"/>
                </mx:ControlBar>

XML在警报中恢复正常,但是Combobox不会填充,我现在尝试了许多不同的方法,有人得到了任何建议吗?我只是盯着它太久了吗?

如果结果(event.result)为xml,那么它应该像这样wotk:

myXmlCollection = new XMLListCollection(event.result.entry.distro);

...这应该在myxmlcollection中创建有效的数据

但此行也是错误的:

distroCombo.dataProvider = myXmlCollection.toString();

它仅在类型字符串的DatapRovider中创建一个项目(BTW:如果您使用Spark Combobox,则在此行中会收到编译错误)。只是使用此方法:

distroCombo.dataProvider = myXmlCollection;

,还要注意,您可以在警报中看到正确的结果,但是它没有说明数据是否正确,coz警报Evertyhing转换为字符串:)

最新更新