将参数传递给 HTTPService 并在 URL 中使用它们
Flex3 + 凯恩戈姆。 我的服务位于 Servicis.mxml 中:
<mx:HTTPService id="docIndex" url="{URL_PREFIX}/jobs/{???}/docs" resultFormat="e4x"/>
我从通用的 Restful 委托中调用它,如下所示:
public function index(params:Object):void {
var call:AsyncToken = services.getHTTPService(resourceName+"Index").send(params);
call.addResponder(responder);
}
我想知道如何使用在 url 定义中传递的 params 对象(上面的 ??? )。 请告诉我你将如何在文档中搜索这个问题的答案,我想对这些问题更加独立......
编辑:如果你不理解我的问题,我会解释一下自己: 我有一个用 Rails 编写的 Restful API,我正在连接它。 Doc 是 Job 的子资源。 如果我想获取所有文档,我也必须提供 job_id。 因此,在服务中,必须为每个 .send() 调用更改 url,并使用正确的 job_id(上面的 ??? 部分)。 我想将其称为 myDelegate.index({job_id:34}) 并将该 job_id 字段插入服务 URL 中。
Flex3 + Cairngorm. I have my service in Servicis.mxml:
<mx:HTTPService id="docIndex" url="{URL_PREFIX}/jobs/{???}/docs" resultFormat="e4x"/>
And I call it from my generic restful delegate like this:
public function index(params:Object):void {
var call:AsyncToken = services.getHTTPService(resourceName+"Index").send(params);
call.addResponder(responder);
}
I want to know how I can use the params Object I pass inside the url definition (the ??? above). And please tell me how you would go about searching an answer to this in the documentation, I'd like to be a little more independet on these problems...
EDIT: I'll explain myself if you didn't understand my problem:
I have a restful api written in rails to which I'm connecting. Doc is a child resource of Job. If I want to get all docs I have to supply a job_id too. Therefore in the service the url must be changed for each .send() call, with the proper job_id (the ??? part above). I'd like to call it like myDelegate.index({job_id:34}) and insert that job_id field in the Service URL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写一个扩展 HTTPService 的类,并允许您将参数设置到 url 中。 然后,在索引函数中,您可以使用 services.getHTTPService 获取它,并调用您创建的为您设置 url 值的函数。
在服务定位器中创建类的实例而不是平面 HTTPService。
Write a class that extends HTTPService and allows you to set parameters into the url. Then, in your index function you can fetch it with services.getHTTPService, and call a function you create that sets the url values for you.
In your service locator create an instance of your class rather than a flat HTTPService.