0

プロジェクトに問題があり、php ファイルから取得した xml データをリストに入力しようとしています。httpservice で php ファイルを呼び出すと、このファイルは xml データを返します。問題があるようですが、エラーは発生しません。デバッグ後、XMLListCollection が null のままであることを知りました。

これが私のコードです:

<?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" 
                 xmlns:components="components.*"
                 creationComplete="httpService.send()">

    <s:layout>
        <s:VerticalLayout paddingTop="20" gap="20" 
                          horizontalAlign="center" />
    </s:layout>
    <fx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.collections.ArrayCollection; 
            import mx.collections.XMLListCollection; 

            import mx.rpc.events.FaultEvent;
            import mx.controls.Alert;
            private var alert:Alert;

            private function httpService_fault(evt:FaultEvent):void {
                var title:String = evt.type + " (" + evt.fault.faultCode + ")";
                var text:String = evt.fault.faultString;
                alert = Alert.show(text, title);
                Bezoekers.removeAll();
            }

            private function httpService_result(evt:ResultEvent):void {
                var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker;
                Bezoekers = new XMLListCollection(xmlList);

            }






        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:HTTPService id="httpService"
                       url="http://localhost/projectnieuw/src/data/bezoekersList.php"
                       resultFormat="e4x"
                       fault="httpService_fault(event);"
                       result="httpService_result(event)" />
        <!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />-->
        <!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>-->
        <s:XMLListCollection id="Bezoekers"/>
    </fx:Declarations>





    <components:Heading/>
    <s:HGroup gap="50">

        <components:BezoekersList bezoekerList="{Bezoekers}" />
        <components:ReservationForm/>

    </s:HGroup>

</s:Application>

何が悪いのか分からないようです。

前もって感謝します

ベルギーからのご挨拶

4

1 に答える 1

0

XMLListCollection がnullBezoekers = new XMLListCollection(xmlList);のままであることは、それに null を与えることを意味します。そのため、まずサーバー側から結果がnullではないことをトレースしてみてください。サーバー側の応答をテストするには、Web ブラウザーで HTTPService の URL を開き、Web ブラウザーで XML データを取得するという 1 つのトリックがあります。成功した場合は、resultFormat="xml"代わりにHTTPService の結果タイプのドキュメントをresultFormat="e4x"読んで使用方法を確認してください。また、XML のケースバイケースのソリューションもいくつかあります。

これがあなたの助けになりますように...

于 2013-01-02T05:09:19.550 に答える