HTTPService 结果 - 检查具有指定名称的项目数量

发布于 2024-08-11 04:45:59 字数 1579 浏览 6 评论 0原文

我对 HTTPService 及其返回的数据有疑问。

好吧,让我们考虑这个 XML:

<PhotoGalleryData>
    <Photo>
        <id>1</id>
        <name>Summer Vacation</name>
        <description>In vacation</description>
        <fullImage>originalImg/1.JPG</fullImage>
    </Photo>
    <Photo>
        <id>2</id>
        <name>Winter Vacation</name>
        <description>coold</description>
        <fullImage>originalImg/2.JPG</fullImage>
    </Photo>
</PhotoGalleryData>

如您所见,我有两个 Photo 实例,可以使用 HTTPService 检索它们,然后在同一 HTTPService 的结果事件上,我希望他计算返回的名为 Photo 的实例是 .lastResult

这是一个愚蠢的问题,但我在 Adob​​e Docs 中找不到它。

当然,我们非常感谢任何帮助、提示、建议。


Medix

我一定是瞎了或者什么的,因为它仍然返回 0。

这里缺少什么?

MXML

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

ActionScript

import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private var xmlData:XMLList;
private var numItems:int;
private function getDataResultHandler(evt:ResultEvent):void
{
    if (evt.result.PhotoGalleryData)
    {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
        Alert.show('Nº '+numItems,'num de Photo');
    }
}

I have a question about HTTPService and the data it returns.

Well lets consider this XML:

<PhotoGalleryData>
    <Photo>
        <id>1</id>
        <name>Summer Vacation</name>
        <description>In vacation</description>
        <fullImage>originalImg/1.JPG</fullImage>
    </Photo>
    <Photo>
        <id>2</id>
        <name>Winter Vacation</name>
        <description>coold</description>
        <fullImage>originalImg/2.JPG</fullImage>
    </Photo>
</PhotoGalleryData>

As you see i have two instances of Photo, that would be retrieved using a HTTPService, well then on the Result Event of that same HTTPService i would want him the count the amount of instances named Photo he as returned on is .lastResult.

This is a dumb question, but i can't find it anywhere in Adobe Docs.

Of course any help, hint, suggestion is greatly appreciated.


Medoix

I gotta be blind or something, because it still returns 0.

Something missing here?

MXML

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

ActionScript

import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
private var xmlData:XMLList;
private var numItems:int;
private function getDataResultHandler(evt:ResultEvent):void
{
    if (evt.result.PhotoGalleryData)
    {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
        Alert.show('Nº '+numItems,'num de Photo');
    }
}

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

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

发布评论

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

评论(2

£冰雨忧蓝° 2024-08-18 04:45:59

在 http_result 函数中,您将将此数据放入 XMLList 中作为示例,然后您可以调用 xmllist.length();

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
    }
}

编辑:执行以下操作...

更改

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

为...

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    resultFormat="e4x";
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

这对我有用。

in the http_result function you have you will be putting this data in an XMLList for an example and then you can call the xmllist.length();

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {
        xmlData = XML(evt.result).descendants("Photo");
        numItems = xmlData.length();
    }
}

EDIT: Do the below...

Change

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

To...

<mx:HTTPService id="getData"
    url="{XMLDataFileLocation}"
    resultFormat="e4x";
    showBusyCursor="true"
    fault="getDataFaultHandler()"
    result="getDataResultHandler(event)"/>

This is working for me.

忱杏 2024-08-18 04:45:59

只需执行以下操作即可。它会解决你的问题;)

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {

        numItems = ArrayCollection(evt.result.PhotoGalleryData.Photo).length;

    }
}

RSTanvir

Just do the following. it will solve your probs ;)

private var xmlData:XMLList;
private var numItems:Integer;

private function HttpResult(evt:ResultEvent):void {
    if (evt.result.PhotoGalleryData) {

        numItems = ArrayCollection(evt.result.PhotoGalleryData.Photo).length;

    }
}

RSTanvir

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