在执行findQuery emberjs和ember data时取消对api的现有调用
Cancel existing calls to the api when doing findQuery emberjs and ember data
我有一个进行实时搜索的输入字段。它被设置为对于每个按键它都做一个存储。findQuery,它触发一个api请求。我注意到,在使用它时,我需要在执行每个新的findQuery时取消对api的挂起ajax调用。随着搜索查询的改变,最终会有大量不相关的请求。有人知道怎么做吗?
没有内置的方法可以做到这一点。ajax调用本身不会返回给您用于这种类型的使用。我建议取消查找请求,以避免产生大量无用的请求。
App.IndexController = Em.Controller.extend({
foo:undefined,
callsToSearch: 0,
actualSearch: 0,
watchFoo: function(){
this.incrementProperty('callsToSearch');
//context, method, time that must elapse before calling method
Em.run.debounce(this, this.doSearch, 300);
}.observes('foo'),
doSearch: function(){
this.incrementProperty('actualSearch');
// do the actual search here
}
});
http://emberjs.jsbin.com/ciyebaqo/1/edit 相关文章:
- 如何在 API 调用后和 if 语句中启用提交按钮
- NodeJS API调用中Array中的Push和Pull元素
- 在Chrome扩展内部输出Google API调用
- IE11中的第二个调用取消了第一个Fetch API调用
- RxjsObservable:通过一个API调用订阅不同的值
- 通过API调用过滤数据
- 给出<选项>标记一个类?API调用不工作
- 使用Angular获取数据API调用时出错
- javascript API调用导致旧数据
- 在一个服务中引用多个API调用(Angular)
- 背景:'userId'在SignUp API调用后为null
- 对/Token的ASP Web API调用间歇性
- Web API 调用在设备模式下失败
- 将使用 $.ajax() 和 JSONP 的 API 调用替换为服务器到服务器的 API 调用
- 如何将 JavaScript Yahoo Weather API 调用属性替换为变量
- 谷歌日历 api 调用可以在角度工厂内返回承诺吗?
- 仅显示 Google 表格中来自 api 调用的最新数据行
- 我的 API 调用没有返回任何内容
- 如何通过声云 api 调用获取用户 ID
- 在 api 调用$resource显示错误和成功消息