2

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

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

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

4

2 回答 2

5

我在选择性地取消商店加载时遇到了类似的问题。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 Direct 连接。

于 2013-03-12T13:57:17.697 回答
0

据我所知,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 );
    }
});
于 2013-05-31T10:15:00.943 回答