Javascript 执行findQuery emberjs和ember数据时取消对api的现有调用

Javascript 执行findQuery emberjs和ember数据时取消对api的现有调用,javascript,ember.js,ember-data,Javascript,Ember.js,Ember Data,我有一个进行实时搜索的输入字段。它的设置使得每次按键都会执行一个store.findQuery,该查询会触发一个api请求。我注意到,在使用它时,我需要在执行每个新的findQuery时取消对api的挂起ajax调用。因为随着搜索查询的改变,最终会有大量与之无关的请求。有人知道怎么做吗?没有内置的方法。对于这种类型的使用,ajax调用本身不会返回给您。我建议您取消find请求,以避免发出大量无用的请求 App.IndexController = Em.Controller.extend({

我有一个进行实时搜索的输入字段。它的设置使得每次按键都会执行一个store.findQuery,该查询会触发一个api请求。我注意到,在使用它时,我需要在执行每个新的findQuery时取消对api的挂起ajax调用。因为随着搜索查询的改变,最终会有大量与之无关的请求。有人知道怎么做吗?

没有内置的方法。对于这种类型的使用,ajax调用本身不会返回给您。我建议您取消find请求,以避免发出大量无用的请求

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
  }
});

有一种更好的方法可以使用Ember.run.debounce例如: