Web服务结果匹配到Flex的请求 [英] Matching web service results to requests in Flex

查看:203
本文介绍了Web服务结果匹配到Flex的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景一点点之前,我可以得到的问题(!):

A little (!) bit of background before I can get to the question :

我有装有网格阵列,其中每个延迟加载符合事物阵列手风琴控制。我使用的是自动生成的Web服务代理来检索这些名单。我想为用户能够改变的选择的子手风琴,而不必等待web服务响应。我原来用的是相同的代理实例的所有请求,并跟踪他们所做的顺序请求,但这个问题是短数组返回更快地从服务器,所以请求是做的顺序变得无关紧要

I have an accordion control loaded with an array of grids, each of which is lazy loaded with arrays of things. I'm using an auto-generated web service proxy to retrieve these lists. I'd like for the user to be able to change the selected child in the accordion without having to wait for the web service to respond. I was originally using the same proxy instance for all requests and keeping track of the requests in the order they were made, but the problem with this is that shorter arrays return more quickly from the server, so the order the requests were made in becomes irrelevant.

我找不到一个明显的方式来确定原始请求处理的代理结果事件所以我结束了是处理change事件手风琴的函数,实例化一个新的web服务的代理时,猛推说成hashtable中与所选择的子项的索引,然后增加了一个封闭件作为事件处理程序。即东西有点像这样的:

I couldn't find an obvious way to determine the original request when handling a proxy result event so what I ended up with is a function which handles the change event on the accordion, instantiates a new webservice proxy, shoves that into a hashtable with the index of the selected child and then adds a closure as an event handler. i.e. something a bit like this :

private proxyTable:Object = new Object();
private function PopulateThingGrid(index:Number):void
{
    var grid:ThingGrid = myAccordion.getChildAt(index) as ThingGrid;
    grid.things = ArrayCollection(proxyTable[index].getThings_lastResult);
}

private function SendThingRequest(index:int):void
{
    var grid:ThingGrid= myAccordion.getChildAt(index) as ThingGrid;
    if (grid.things.length == 0)
    {
    	if (proxyTable[index] == null)
    	{
    		proxyTable[index] = new MyWebServiceProxy();
    	}
    	var proxy:MyWebServiceProxy= proxyTable[index];
    	proxy.addgetThingsEventListener(function ():void { PopulateThingGrid(index); });

    	var list:ThingList = thingLists.getItemAt(index) as ThingList;
    	proxy.getThings("thinglist", list.ListID);
    }
}

private function myAccordion_Change(event:IndexChangedEvent):void
{
    SendThingRequest(event.newIndex);
}

(我一直在努力,这个匿名化了一点,所以我可能错过了一些东西,但希望你的想法)

(I've tried to anonymise this a bit, so I may have missed something, but hopefully you get the idea)

所以,这个问题(S):有没有一种简单的方法来匹配代理的结果与原来的请求,我只是缺少

So, to the question(s) : is there an easier way to match up proxy results with the original requests that I'm just missing?

如果不是,是我做了什么合理?我有点担心,我可能最终产生,然后处置它们正确的代理实例的数量(时必要) - 是否有任何缺陷我可能不知道

If not, is what I've done reasonable? I'm a little concerned about the number of proxy instances that I could end up generating and then disposing of them correctly (when that becomes necessary) - are there any pitfalls I might not be aware of?

更新: 我认为,原因可能在于,生成的代理code子类的ResultEvents从对象类型:flash.events.Event,而不是mx.rpc.events.ResultEvent问题。我不完全知道为什么它这样做 - 访问的AsyncToken是当它最初是由方法调用返回的唯一方法

Update : I think the problem may arise because the generated proxy code subclasses the ResultEvents from flash.events.Event, rather than mx.rpc.events.ResultEvent. I'm not entirely sure why it does this - the only way to access the AsyncToken is when it's initially returned by the method call.

推荐答案

不知道这会有所帮助,但我也有类似的情况,我在那里有一个RemoteObject的对我称之为4 CRUD方法,但只有一个resultHandler。我用这个解决的标记的AsyncToken

Not sure if this helps, but I had a similar situation, where I had a RemoteObject on which I call the 4 CRUD methods, but only one resultHandler. I solved this using the AsyncToken.

我的RemoteObject的电话是这样的:

My RemoteObject calls looked like this:

public function list() {
    var token:AsyncToken = myService.list();
    token.operation = "list";
}

public function update() {
    var token:AsyncToken = myService.update(selectedItem);
    token.operation = "update";
}

public function create() {
    var token:AsyncToken = myService.create(selectedItem);
    token.operation = "create";
}

public function delete() {
    var token:AsyncToken = myService.delete(selectedItem);
    token.operation = "delete";
}

然后, resultHandler 是这样的:

public function resultHandler(event:ResultEvent):void {
    if( event.token.operation == "list" ) {
      // do something
    }   else if( event.token.operation == "update" ) {
    // do something
    }   
    // etc...

操作是一个动态的属性,而不是对标记的AsyncToken的成员,所以你可以把它叫做任何你喜欢的。 有一个食谱文章描述它<一个href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&postId=922&productId=2"相对=nofollow>这里:

operation is a dynamic property, not a member of AsyncToken, so you can call it whatever you like. There's a Cookbook article describing it here:

这篇关于Web服务结果匹配到Flex的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆