2015-07-03 103 views
1

我有一个5000毫秒超时的ajax TreeStore,并且当查询执行时间超过超时时,我想捕获该事件。我该怎么做?ExtJS当查询执行时间超过超时时捕获事件

我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事件。当一切正常时,我抓到beforeloadload

回答

0

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

+0

谢谢,在你的例子中所有的作品,因为我的期望,但我不能让它在我的代码工作。我试图更深入地检查我的代码。 –

0

Ajax存储代理在后台使用Ext.Ajax向服务器发送HTTP请求。你可以在Ext.Ajax单身,这样的注册requestexception event处理程序:

Ext.Ajax.on('requestexception', function() { 
    console.log('HTTP error'); 
}); 

只是要小心,因为此事件处理程序将被无论解雇谁发起请求,以便它是全系统(全球),而不是特定于组件发起请求(Portal.store.ObjectsTreeStore您的情况)。