【问题标题】:Selectively aborting an ajax request sent via Extjs Direct proxy选择性地中止通过 Extjs Direct 代理发送的 ajax 请求
【发布时间】:2012-11-06 12:50:35
【问题描述】:

我有一个商店,它使用 Extjs 直接代理从列表中加载 w.r.t 项目。

   proxy : {
                type: 'direct',
                api: {
                    read: bomManagementAction.bomQuickDetails
                }                      
              }

响应显示在网格面板中。
如果选择的项目数量较多,则需要很长时间才能完成,因此如果等待较长的请求并且我们发送了较短的请求,则网格肯定会更新为后者,但是当前者请求时会发生什么情况完成后,网格将重新更新为前一个,这是不可取的。我知道 'autoabort' 配置存在于 'Ext.data.Connection' 类中,但不存在于 proxy.direct ...
请帮助

【问题讨论】:

    标签: extjs4.1


    【解决方案1】:

    我在选择性地取消存储加载时遇到了类似的问题。 Ext.Ajax.abort(request) 能够中止请求。但是很难从存储中获取当前的请求对象(或者更好的是,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();
    ...
    

    不好,但持久的存储加载被可靠地取消了。

    也许可以将这一想法转变为 Extjs 直接连接。

    【讨论】:

    【解决方案2】:

    据我所知,Ajax.abort() 不适用于直接调用(看起来发送到服务器的请求与从服务器返回的请求不同,因为直接引擎在两者之间做自己的事情)。

    虽然我不确定我是否直接回答你的问题,但我有一个类似的场景,解决方案是这样的:

    /**
     * A proxy class that ensures only the reponse to the last read request is 
     * processed.
     *
     * A quick user actions may result in more than one request sent to the server,
     * but it is possible for the server to return a response to the second request
     * before returning that of the first request. This will mean the the store
     * will be populated with records that do not correspond to the latest user
     * action.
     *
     */
    
    Ext.define('Ext.data.proxy.SerialDirect', {
    
        extend: 'Ext.data.proxy.Direct',
        alternateClassName: 'Ext.data.DirectSerialProxy',
    
        alias: 'proxy.serialdirect',
    
        doRequest: function(operation, callback, scope) {
            this.callParent( arguments );
    
            // Store the last read request
            if ( operation.request.action == "read" ) {
                this.lastReadRequest = operation.request;
            }
        },
    
        processResponse: function(success, operation, request, response, callback, scope) {            
            // abort if the request is a read one and does not correspond to the
            // last read request
            if ( request.action == "read" && request != this.lastReadRequest )
                return;
    
            this.callParent( arguments );
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 2010-12-03
      • 2017-04-28
      相关资源
      最近更新 更多