Ajax存储代理在后台使用Ext.Ajax向服务器发送HTTP请求。您可以在Ext.Ajaxsingleton上注册requestexception事件处理程序,如下所示:
我有一个超时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
事件。当一切正常时,我抓住beforeload
和load
。
只需将异常侦听器附加到代理而不是存储。参见示例:https://fiddle.sencha.com/#fiddle/psj
Ext.Ajax.on('requestexception', function() {
console.log('HTTP error');
});
请小心,因为无论是谁发出请求,都会触发此事件处理程序,因此它是系统范围的(全局的(,而不是特定于发出请求的组件(在您的情况下为Portal.store.ObjectsTreeStore
(。