HTTPService 将地理编码结果返回到 DataGrid 的问题

发布于 2024-10-10 06:11:42 字数 1890 浏览 2 评论 0原文

我正在创建一个 Flex3 应用程序,以从 Google 地理编码 API 返回一些结果

我使用 TourDeFlex 中的 HTTPService 事件示例作为参考指南模仿。

目前,我已对 Google 的响应进行了硬编码以使用此 XML 响应: 地图.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

网络监视器表明我从 XML 中获得了有效响应,但我想我没有正确引用它来填充我的 DataGrid?

我已在此处截屏了该问题。

这是我的代码的精简版本:

private function resultHandler(event:ResultEvent):void
        {
        results = event.result.GeocodeResponse.result;
        }

        private function faultHandler(event:FaultEvent):void
        {
        Alert.show(event.fault.faultDetail, "Error");
        }           

    ]]>
</mx:Script>

<mx:HTTPService id="srv" 
            url="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&amp;sensor=false"
        result="resultHandler(event)"
            fault="faultHandler(event)"/>

<mx:TitleWindow title="Find" showCloseButton="true" close="closeMe();"
            styleName="formPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off"
            width="400" height="200">

    <mx:DataGrid dataProvider="{results}" width="100%" height="100%">
        <mx:columns>
        <mx:DataGridColumn dataField="type" headerText="Address"/>
        </mx:columns>
    </mx:DataGrid>

  <mx:Button label="Go" height="20" styleName="buttonGo" click="srv.send()"/>
</mx:TitleWindow>

I am creating a Flex3 app to return some results from the Google Geocoding API.

I am using the HTTPService Events sample from TourDeFlex as a reference guide to mimic.

For now, I have hardcoded the response from Google to use this XML response:
maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false

Network Monitor suggests that I am getting a valid response from the XML, but I imagine I have not referenced it correctly for populating my DataGrid?

I have screencasted the issue here.

Here is a stripped down version of my code:

private function resultHandler(event:ResultEvent):void
        {
        results = event.result.GeocodeResponse.result;
        }

        private function faultHandler(event:FaultEvent):void
        {
        Alert.show(event.fault.faultDetail, "Error");
        }           

    ]]>
</mx:Script>

<mx:HTTPService id="srv" 
            url="http://maps.googleapis.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false"
        result="resultHandler(event)"
            fault="faultHandler(event)"/>

<mx:TitleWindow title="Find" showCloseButton="true" close="closeMe();"
            styleName="formPanel" horizontalScrollPolicy="off" verticalScrollPolicy="off"
            width="400" height="200">

    <mx:DataGrid dataProvider="{results}" width="100%" height="100%">
        <mx:columns>
        <mx:DataGridColumn dataField="type" headerText="Address"/>
        </mx:columns>
    </mx:DataGrid>

  <mx:Button label="Go" height="20" styleName="buttonGo" click="srv.send()"/>
</mx:TitleWindow>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙幽之幻 2024-10-17 06:11:42

看了一下xml。第一次出现的 type 可能位于顶层,但从那时起 type 就成为 address_component 的元素。

也许尝试 address_component.type 作为 DataGridColumn 的数据字段?或者将 dataprovider 设置为 results.address_component?

编辑更新

因为它读取XML,所以可以在标签内设置resultFormat="e4x",并有一个XMLListCollection等待结果:

<mx:XMLListCollection id="xc" source="{srv.lastResult.result}"/>

<mx:DataGrid id="dg" dataProvider="{xc}">

在调试模式下,在 XC 上设置监视以确保其已填充

Had a look at the xml. It could be that the first occurance of type is at a top level, but from then on type is an element of address_component.

Maybe try address_component.type as the datafield of the DataGridColumn? Or set the dataprovider to results.address_component?

Edit Update

Because its reading XML, maybe set resultFormat="e4x" inside the <HttpService ..> tag, and have an XMLListCollection awaiting the result:

<mx:XMLListCollection id="xc" source="{srv.lastResult.result}"/>

<mx:DataGrid id="dg" dataProvider="{xc}">

In debug mode, set a watch on XC to make sure its being populated

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文