Type Coercion failed: cannot convert XMLList@106e9af1 to mx.collections.IList

不打扰是莪最后的温柔 提交于 2019-12-11 11:23:46

问题


using code blew I am trying to parse the following soap response.

<?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.*"
               xmlns:hellos="services.hellos.*"
               height="957"  creationComplete="initApp()" > 
    <fx:Style source="Styles.css"/>
    <fx:Script>

        <![CDATA[

            import mx.controls.Alert;

            private namespace invesbot = "http://Services.com";
            use namespace invesbot;

            private namespace a = "http://schemas.xmlsoap.org/soap/envelope/";
            private namespace b = "http://www.w3.org/2001/XMLSchema"; 
            private namespace c = "http://www.w3.org/2001/XMLSchema-instance";
            use namespace a;
            use namespace b;
            use namespace c;

            [Bindable]
            var _result:*



            private function initApp():void
            {
                myService.mycustomers();
            }

        ]]> 
    </fx:Script>
    <fx:Declarations>
        <mx:WebService id="myService" wsdl="http://localhost:8081/WebServiceTest/services/Hellos?wsdl" 
                       showBusyCursor="true" 
                       fault="Alert.show(event.fault.faultString), 'Error'">
            <mx:operation name="mycustomers" resultFormat="e4x">
                <mx:request>
                </mx:request>
            </mx:operation>
        </mx:WebService>

    </fx:Declarations>
<mx:HBox>
        <mx:Text
            text="{myService.mycustomers.lastResult.mycustomersReturn.name}"
            />
    </mx:HBox>
</s:Application>

The SOAP response is as following

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <mycustomersResponse xmlns="http://Services.com">
      <mycustomersReturn>
        <age>28</age>
        <name>John</name>
      </mycustomersReturn>
      <mycustomersReturn>
        <age>29</age>
        <name>Alex</name>
      </mycustomersReturn>
      <mycustomersReturn>
        <age>30</age>
        <name>Jack</name>
      </mycustomersReturn>
    </mycustomersResponse>
  </soapenv:Body>
</soapenv:Envelope>

Using the above code the output will be

<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">John</name>
<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Alex</name>
<name xmlns="http://Services.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Jack</name>

but when I use the following code to put the result in dropdown box it gives the following error

<s:FormItem label="Employee:"> 
        <s:DropDownList id="dropDownList3"
                        labelField="name"
                        dataProvider ="{myService.mycustomers.lastResult.mycustomersReturn}"/>
    </s:FormItem>

TypeError: Error #1034: Type Coercion failed: cannot convert XMLList@106e9af1 to mx.collections.IList.


回答1:


You have to wrap your data in an XMLListCollection The same thing with Arrays, you'll have to wrap them into ArrayCollections. With the new version of flex sdk 4.9 you can also create VectorLists and VectorCollections.

For example:

var iList:IList =  new XMLListCollection(myService.mycustomers.lastResult.mycustomersReturn);
dataProvider = iList;


来源:https://stackoverflow.com/questions/14331106/type-coercion-failed-cannot-convert-xmllist106e9af1-to-mx-collections-ilist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!