簡體   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