ExtJs 4:远程组合框 - 中止先前的请求

one*_*ind 2 combobox typeahead ajax-request extjs4

就像标题所说,我想中止之前的ajax请求.每当用户键入请求数据的字母(或数字)时,组合框请求通过ajax,就像我通过ajax说的那样,然后将数据返回到组合框.

我的问题是每当我在字段中输入用户输入时,ajax请求就会堆积起来.

我想要做的是先中止先前的请求然后继续当前的请求.我试过这段代码:

  comboObj.onTypeAhead = Ext.Function.createInterceptor(comboObj.onTypeAhead, function() {
     Ext.Ajax.abort(); //aborts the last Ajax request
     return true; //runs the onTypeAhead function
  });
Run Code Online (Sandbox Code Playgroud)

那没用,然后尝试了这个:

  ......
  listeners: {
        beforequery: function(evt){
           Ext.Ajax.abortAll(); //cancel any previous requests
           return true;
        }
     }
Run Code Online (Sandbox Code Playgroud)

这对我来说不起作用,因为我有一个也使用ajax请求的计时器,如果执行了监听器,它也将被取消.

我该怎么做呢?

Eri*_*ter 6

我花了很长时间才弄明白.Ext.Ajax.abort(请求)能够中止请求.但是从商店获取当前请求对象(或更好,请求对象Ext.Ajax.abort需要)非常困难.

最后我得到了这个:

...
if (store.loading && store.lastOperation) {
  var requests = Ext.Ajax.requests;
  for (id in requests)
    if (requests.hasOwnProperty(id) && requests[id].options == store.lastOperation.request) {
      Ext.Ajax.abort(requests[id]);
    }
}
store.on('beforeload', function(store, operation) {
  store.lastOperation = operation;
}, this, { single: true });

store.load();
...
Run Code Online (Sandbox Code Playgroud)

不太好但持久的存储负载可靠地取消.