查询执行时间超过超时时发生ExtJS Catch事件

ExtJS Catch event when query execution time exceeds the timeout

本文关键字:ExtJS Catch 事件 执行时间 超时 查询      更新时间:2023-09-26

我有一个超时5000毫秒的ajax树存储,我想在查询执行时间超过超时时捕获事件。我该怎么做?

我的树商店:

Ext.define('Portal.store.ObjectsTreeStore', {
    extend: 'Ext.data.TreeStore',
    model: 'Portal.model.ObjectsTreeModel',
    proxy: {
        type: 'ajax',
        url: 'my/url.json',
        timeout: 5000, // 5 seconds
        reader: {
            type: 'json',
            successProperty: 'success',
            messageProperty: 'message'
        }
    },
    listeners: {
        beforeload: function() {
            console.log('1');    
        },
        load: function() {
            console.log('2');    
        },
        exception: function() {
            console.log('3');    
        }
    }
});

使用此代码,我只在超过查询执行时间并取消请求时捕获beforeload事件。当一切正常时,我抓住beforeloadload

只需将异常侦听器附加到代理而不是存储。参见示例:https://fiddle.sencha.com/#fiddle/psj

Ajax存储代理在后台使用Ext.Ajax向服务器发送HTTP请求。您可以在Ext.Ajaxsingleton上注册requestexception事件处理程序,如下所示:
Ext.Ajax.on('requestexception', function() {
    console.log('HTTP error');
});

请小心,因为无论是谁发出请求,都会触发此事件处理程序,因此它是系统范围的(全局的(,而不是特定于发出请求的组件(在您的情况下为Portal.store.ObjectsTreeStore(。