是否有可能取消微风请求(AngularJS)? [英] Is it possible to cancel Breeze requests (AngularJS)?

查看:183
本文介绍了是否有可能取消微风请求(AngularJS)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一种方法来取消BreezeJS查询实现实时搜索,查询BreezeJS关键preSS的目的(见我的其他问题)。

I'm trying to find a way to cancel BreezeJS queries for the purpose of implementing a live search that queries BreezeJS on keypress (see my other question).

我知道,在棱角分明, $ HTTP 请求可以通过传递一个承诺到暂停参数取消在配置对象,然后调用解析()这一承诺。

I know that in Angular, $http requests can be cancelled by passing a promise to the timeout parameter in the config object, and then calling resolve() on that promise.

我也知道,我能得到BreezeJS用我的模块的 $ HTTP insance有:

I also know that I can get BreezeJS to use my module's $http insance with:

var ajax = breeze.config.initializeAdapterInstance('ajax', 'angular');
ajax.setHttp($http);

所以我在想可能是创建一个要求拦截器在 $ HTTP 将设置 config.timeout 来一个承诺。但是,这仍然让我相当几步之遥解决这个问题,因为我会以某种方式需要能够从code运行查询(给的承诺我的拦截器,以使查询code能如果需要解析()的承诺)。

So I was thinking about possibly creating a request interceptor on $http that would set config.timeout to a promise. But that still leaves me quite a few steps away from solving the problem, because I would somehow need to be able to give the promise to my interceptor from the code running the query (so that the querying code could resolve() the promise if needed).

有没有更好的办法?它甚至有可能?

Is there a better way? Is it even possible?

推荐答案

您可以使用AJAX适配器的 requestInterceptor 设置HTTP级别的超时和取消的v.1.4.12的。查看文档,控制AJAX调用

Update 16 May 2014

You can set HTTP-level timeout and cancellation with the AJAX Adapter's requestInterceptor as of v.1.4.12. See the documentation, "Controlling AJAX calls".

的EntityManager HTTP服务业务不提供取消或超时选项。也许他们有一天会。

The EntityManager HTTP service operations don't offer cancel or timeout options. Maybe they will someday.

在v.1.4.11微风 AJAX适配器不提供取消或超时选项要么。 但他们会在v.1.4.12 的,你可以看到在github上的preVIEW现在。

The v.1.4.11 Breeze AJAX adapters don't offer cancel or timeout options either. But they will in v.1.4.12 and you can see the preview on github right now.

在GitHub上的示例说明这两种新的适配器取消和超时。对于jQuery的AJAX组件的用户有<一个href="https://github.com/Breeze/breeze.js.samples/blob/master/net/Doc$c$c/Doc$c$c/tests/jQueryAjaxAdapterTests.js"相对=nofollow称号=医生code jQuery的适配器测试> 文档code :jQueryAjaxAdapterTests.js 的。对于用户角的 $ HTTP 还有就是<一个href="https://github.com/Breeze/breeze.js.samples/blob/master/node/zza-node-mongo/client/test/specs.async/ajax-adapter.async.spec.js"相对=nofollow称号=ZZA角适配器测试> ZZA节点 - 蒙戈:AJAX-adapter.async.spec.js

The samples on github illustrate both cancel and timeout with the new adapters. For users of the jQuery AJAX component there is DocCode:jQueryAjaxAdapterTests.js. For users of Angular's $http there is the Zza-Node-Mongo:ajax-adapter.async.spec.js.

这是最好的,如果你可以运行样品,但如果你不能(也许是因为你不使用所涉及的技术之一),测试文件(见上面的链接)易于阅读,你应该搜集的想法这将有助于。至少我希望如此。

It's best if you can run the samples but if you can't (perhaps because you don't use one of the technologies involved), the test files (see links above) are easy to read and you should glean the ideas that will help. At least I hope so.

取消和超时非常有用的功能。你需要他们为你的使用情况?有可能。但是你要采取的第一个步骤去弹跳用户进入你的生活搜索的文字,让你不会发射了毫无意义的查询100秒。

Cancel and timeout are useful features. Do you need them for your use case? Maybe. But you'd want to take a first step of de-bouncing the text that users enter into your "live search" so that you aren't firing off 100s of pointless queries.

这个意见在<一个讨论href="http://stackoverflow.com/questions/23436699/$p$pserving-asynchronous-query-order-in-breeze-angular">your相关的StackOverflow问题。

这篇关于是否有可能取消微风请求(AngularJS)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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