Flex RemoteObject-处理多个请求 [英] Flex RemoteObject - handling multiple requests

查看:105
本文介绍了Flex RemoteObject-处理多个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个远程对象方法,我想根据上下文以不同的方式响应它们,但是我不想设置一堆不同的RemoteObject别名.有什么建议吗?一些背景:

I have a couple of remote object methods that I want to respond to in different ways depending on the context, but I'd rather not set up a bunch of different RemoteObject aliases. Any advice on doing that? Some background:

假设我有一个管理应用程序,该应用程序以不同的方式显示销售统计信息.远程方法如下:

Let's say I have an admin application that displays sales stats in different ways. The remote method looks like:

<mx:RemoteObject id="rpt" destination="AMFServer">
  <mx:method name="getSalesStats" fault="getSalesStatsFault(event)" 
    result = "getSalesStatsSuccess(event)" />
</mx:RemoteObject>

getSalesStats方法将员工ID和销售类型作为其参数.您可以这样称呼它:

The getSalesStats method takes an employee ID and a sales type as its arguments. You'd call it like:

rpt.getSalesStats(120, "peanuts");

public function getSalesStatsSuccess(e:ResultEvent):void {
   salesdata:ArrayCollection = e.result.rows as ArrayCollection; 
   salesGraph.dataProvider = salesdata; 
   salesGraphPanel.title = "Peanut Sales, 1990";
}

我希望能够在不同的上下文中调用此方法,有时将结果发送到图表,有时发送到数据网格;我希望能够根据用户的需要更改图表的标题和类型.通过评估服务器返回的数据可以实现我想要的某些功能.该对象包含报告名称,因此我可以评估该值.但是,除了我从服务器获得的收益以外,还需要根据其他方面进行一些更改.如果这是一个同步调用,那将很容易.我会做类似的事情:

I want to be able to call this method in different contexts, sometimes sending the result to a chart and sometimes to a datagrid; I want to be able to change the title and type of chart depending on what the user wants. Some of what I want can be achieved by evaluating the data returned from the server; the object contains the report name, so I can evaluate that value. But some things need to change based on more than just what I get back from the server. If this was a synchronous call, it would be easy; I'd do something like:

function buttonOneClick():void {
   myData1:ArrayCollection = getSalesStats(120, "peanuts");
   myChart.dataProvider = myData1;
}

function buttonTwoClick():void {
   myData2:ArrayCollection = getSalesStats(120, "cashews");
   myDataGrid.dataProvider = myData2; 
}

我想通过远程方法将某些内容传递给响应函数,例如:

I'd like to pass something through the remote method to the responding function, like:

rpt.getSalesStats(120, "peanuts", "clicked button one");

但这当然会引发错误,因为服务器不需要最后一个参数.有什么想法吗?我会澄清这是否令人困惑.

but that of course throws an error because the server doesn't want that last argument. Any thoughts? I'll clarify if this is confusing..

推荐答案

在Flex 4和3.4中,使用CallResponder类:

In Flex 4 and 3.4, use the CallResponder class:

<mx:RemoteObject id="rpt" destination="AMFServer"/>
<s:CallResponder id="toChartResponder" fault="getSalesStatsFault(event)" 
        result = "getSalesStatsToChartSuccess(event)" />
<s:CallResponder id="toDataGridResponder"fault="getSalesStatsFault(event)" 
        result = "getSalesStatsToDataGridSuccess(event)"/>

要进行调用,请将方法调用中返回的AsyncToken分配给响应者的token属性:

To make the call, assign the returned AsyncToken from the method call to the token property of the responder:

toDataGridResponder.token = rpt.getSalesStats();

这将响应定义与方法调用分开,然后您可以将其包装在所需的任何逻辑中.

This separates the response definition from the method call, and you can then wrap it in whatever logic you need.

这篇关于Flex RemoteObject-处理多个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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