当查询执行时间超过超时时,ExtJS Catch 事件
ExtJS Catch event when query execution time exceeds the timeout
我有一个超时为 5000 毫秒的 ajax TreeStore,我想在查询执行时间超过超时时捕获事件。我该怎么做?
我的 TreeStore:
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
事件。当一切正常时,我赶上 beforeload
和 load
.
Ajax store 代理使用 Ext.Ajax in the background to send HTTP requests to the server. You could register requestexception event handler on Ext.Ajax 单例,像这样:
Ext.Ajax.on('requestexception', function() {
console.log('HTTP error');
});
请小心,因为无论是谁发出请求都会触发此事件处理程序,因此它是系统范围的(全局的)并且不特定于发起请求的组件(Portal.store.ObjectsTreeStore
在您的情况下)。
只需将您的异常侦听器附加到代理而不是商店。参见示例:https://fiddle.sencha.com/#fiddle/psj
我有一个超时为 5000 毫秒的 ajax TreeStore,我想在查询执行时间超过超时时捕获事件。我该怎么做?
我的 TreeStore:
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
事件。当一切正常时,我赶上 beforeload
和 load
.
Ajax store 代理使用 Ext.Ajax in the background to send HTTP requests to the server. You could register requestexception event handler on Ext.Ajax 单例,像这样:
Ext.Ajax.on('requestexception', function() {
console.log('HTTP error');
});
请小心,因为无论是谁发出请求都会触发此事件处理程序,因此它是系统范围的(全局的)并且不特定于发起请求的组件(Portal.store.ObjectsTreeStore
在您的情况下)。
只需将您的异常侦听器附加到代理而不是商店。参见示例:https://fiddle.sencha.com/#fiddle/psj