ExtJs 4:远程组合框 - 中止上一个请求 [英] ExtJs 4: Remote Combobox - Abort Previous Request

查看:208
本文介绍了ExtJs 4:远程组合框 - 中止上一个请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Like the title says, I would like to abort the previous ajax request. The combobox request through ajax whenever a user types in letters(or numbers) it request data, like I said through ajax, then returns the data back to the combobox.

我的问题是每当我在该字段中输入用户输入时,ajax请求将堆积。

My problem is that the ajax request will pile up whenever I put a user inputs in the field.

我想要做的是首先中止先前的请求,然后继续到当前请求。我试过这个代码:

What I want to do is to abort first the previous request then proceed to the present request. I tried this code:

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

没有工作,然后尝试:

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

定时器也使用ajax请求,如果监听器被执行也会被取消。

That did not work for me either because I have a timer that also uses ajax request, which will also be cancelled if the listener is executed.

我如何做?

推荐答案

这需要我很长时间才能弄清楚。
Ext.Ajax.abort(request)能够中止请求。但是很难从商店获得当前的请求对象(或者更好的是请求对象Ext.Ajax.abort的需要)。

It took me a long time to figure it out. Ext.Ajax.abort(request) is able to abort requests. But it is pretty hard to get the current request object (or better, the request object Ext.Ajax.abort needs) from a store.

最后我得到这个: / p>

Finally I got this:

...
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();
...

不太好,但持久的商店装载可以取消。

Not nice but lasting store loads are reliably canceled.

这篇关于ExtJs 4:远程组合框 - 中止上一个请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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