ExtJS setTimeout调用函数,但在销毁视图后,我收到一些错误
我有一个函数,3000秒后调用其他函数检查网格的新数据ExtJS setTimeout调用函数,但在销毁视图后,我收到一些错误,extjs,extjs4,extjs4.1,extjs4.2,Extjs,Extjs4,Extjs4.1,Extjs4.2,我有一个函数,3000秒后调用其他函数检查网格的新数据 onViewDestroy: function(view) { console.log('view destroy'); var me = this; if(me.timer) clearTimeout(me.timer); }, afterRender: function(){ // start timer to load log grid in 3 secs
onViewDestroy: function(view) {
console.log('view destroy');
var me = this;
if(me.timer) clearTimeout(me.timer);
},
afterRender: function(){
// start timer to load log grid in 3 secs
me.logTimer = setTimeout(Ext.bind(me.checkProcessLog, me), 3000);
},
checkProcessLog: function() {
console.log('check process log');
var me = this,
requestGrid = me.getRequestGrid(),
logGrid = me.getProcessLog(),
logStore = logGrid.getStore();
var selectedRecord = requestGrid.getSelectionModel().getSelection()[0];
// if the grid is expanded and the status of the process is pending or in progress
if (!logGrid.collapsed && (selectedRecord.get('Status') == 0 || selectedRecord.get('Status') == 1)) {
logStore.load({
callback: function(records, op, success) {
if (success) {
// start timer to load again log grid in 3 secs
me.logTimer = setTimeout(Ext.bind(me.checkProcessLog, me), 3000);
}
}
});
}
},
我遇到的问题是,如果在调用函数时关闭视图(销毁),则所有变量如下:
requestGrid = me.getRequestGrid(),
logGrid = me.getProcessLog(),
logStore = logGrid.getStore();
我得到一个错误:
无法读取未定义的属性“getStore”
这是有道理的,因为视图已被破坏。任何避免这种情况的解决方法?只需简单检查即可:
requestGrid = me.getRequestGrid(),
logGrid = me.getProcessLog();
if(!logGrid) return false
logStore = logGrid.getStore();
这也将停止调用函数