簡體   English   中英

在Flex中用XML填充組合框

[英]Populating a combobox with XML in Flex

我正在嘗試使用XML文件中的國家/地區填充組合框。 不幸的是,組合框沒有被填充。 我應該如何解決這個問題? 提前致謝!

這是我的代碼:

protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void
{
    fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox);    
    fillCboCountries.send();        
}


protected function fillCombobox(event:ResultEvent):void
{           
    cboCountries.dataProvider=event.result.global.countryItem;              
}

<fx:Declarations>
<s:HTTPService id="fillCboCountries" url="https://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"/>  
</fx:Declarations>  

<s:ComboBox id="cboCountries" x="10" y="414" width="173" labelField="countryLabel"/>

您的代碼沒有錯誤。 我已經將其粘貼到我的空項目中,並且在組合框中看到了您的字段。

我唯一更改的是盡管有https的http。

因此,問題出在數據源中,而不是源代碼中! 不使用https即可嘗試。

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
           xmlns:s="library://ns.adobe.com/flex/spark" 
           xmlns:mx="library://ns.adobe.com/flex/mx" 
           minWidth="955" minHeight="600" 
           creationComplete="navigatorcontent2_creationCompleteHandler(event)">

<fx:Declarations>
    <s:HTTPService id="fillCboCountries" url="http://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"/>  
</fx:Declarations>  

<fx:Script>
    <![CDATA[
        import mx.events.FlexEvent;
        import mx.rpc.events.ResultEvent;

        protected function navigatorcontent2_creationCompleteHandler(event:FlexEvent):void
        {
            fillCboCountries.addEventListener(ResultEvent.RESULT, fillCombobox);    
            fillCboCountries.send();        
        }

        protected function fillCombobox(event:ResultEvent):void
        {           
            cboCountries.dataProvider=event.result.global.countryItem;              
        }
    ]]>
</fx:Script>

<s:ComboBox id="cboCountries" x="10" y="414" width="173" labelField="countryLabel"/>
</s:Application>

在沒有看到來自服務調用的XML響應的情況下,我唯一可以建議的就是將HTTPService上的resultFormat設置為“ e4x”:

<s:HTTPService id="fillCboCountries"
    url="https://marnixcoosemans2013.dreamhosters.com/scripts/countries_select.php"
    resultFormat="e4x" />

這告訴HTTPService響應是XML,您希望使用e4x表達式獲取數據。

謝謝大家的幫助。

我通過將代碼復制到新項目中來解決了該問題。 不幸的是,我不知道原始項目出了什么問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM