Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Extjs 确保仅处理对最新(直接)代理读取请求的响应_Extjs_Extjs4.1 - Fatal编程技术网

Extjs 确保仅处理对最新(直接)代理读取请求的响应

Extjs 确保仅处理对最新(直接)代理读取请求的响应,extjs,extjs4.1,Extjs,Extjs4.1,在我正在开发的日历系统中,从服务器上选择日期获取该日期的事件 问题是,如果用户在日期之间快速切换,有时第二个请求的响应会在第一个请求的响应之前返回,从而导致存储被错误的记录(第一个请求的记录,即错误的日期)填充 我曾尝试使用Ext.Ajax.abort(),但这似乎不适用于直接调用 所以问题是如何确保代理只处理最新请求的响应 我提出的解决方案如下。可以从直接代理类派生,以确保此类行为: /** * A proxy class that ensures only the reponse to t

在我正在开发的日历系统中,从服务器上选择日期获取该日期的事件

问题是,如果用户在日期之间快速切换,有时第二个请求的响应会在第一个请求的响应之前返回,从而导致存储被错误的记录(第一个请求的记录,即错误的日期)填充

我曾尝试使用
Ext.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 );
    }
});

可以从直接代理类派生,以确保此类行为:

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