繁体   English   中英

从PHP的XML填充Flex ComboBox

[英]Populate Flex ComboBox from XML from PHP

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

这是弹性代码:

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在Alert中恢复正常,但comboBox不会填充,我现在已经尝试了很多不同的方法,有人对此有何建议? 我只是盯着它太久了吗?

如果结果(event.result)是XML,则它应该像这样wotk :(与您的结果相比,.distro最终有所不同)

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

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

但是这行也是错误的:

distroCombo.dataProvider = myXmlCollection.toString();

它将在dataProvider中仅创建一个字符串类型的项(只是BTW:如果您将使用spark组合框,则在此行会出现编译错误)。 只需使用此代替:

distroCombo.dataProvider = myXmlCollection;

还要注意,您可以在Alert中看到正确的结果,但是并没有说明数据的类型是否正确,coz Alert evertyhing会转换为string :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM