从PHP中的XML填充Flex ComboBox

时间:2014-02-02 09:56:07

标签: php xml flex combobox

我无法从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>

可能是最基本的XML形式!

这是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>

在Alert中返回的XML很好但是comboBox不会填充,我现在尝试了这么多不同的方法,有人有任何建议吗?我是不是一直盯着它看太久了?

1 个答案:

答案 0 :(得分:1)

如果结果(event.result)是XML,那么它应该像这样:(它与.distro相比最终与你的相比)

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

...这应该在myXmlCollection

中创建有效数据

但是这一行也错了:

distroCombo.dataProvider = myXmlCollection.toString();

它只在字符串类型的dataProvider中创建一个项目(Just BTW:如果你使用了spark combobox,你会在这一行得到编译错误)。 只需使用它:

distroCombo.dataProvider = myXmlCollection;

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

相关问题