HTTPService 结果 - 检查具有指定名称的项目数量
我对 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
。
这是一个愚蠢的问题,但我在 Adobe 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 http_result 函数中,您将将此数据放入 XMLList 中作为示例,然后您可以调用 xmllist.length();
编辑:执行以下操作...
更改
为...
这对我有用。
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();
EDIT: Do the below...
Change
To...
This is working for me.
只需执行以下操作即可。它会解决你的问题;)
RSTanvir
Just do the following. it will solve your probs ;)
RSTanvir