Ext 2-iframe bug
在Ext2.0 Beta1中 在嵌套iframe时出现Ext.getBody() 返回undefined现象,经过排查,发现是js的执行顺序问题,Ext.onReady被过早的执行。继续寻求答案,最后发现这应该是Ext的一个bug。
解决方法:
修改EventManager.js
主要分为两个代码片段:
第一个代码片段修改前
var fireDocReady = function(){ if(!docReadyState){ docReadyState = true; Ext.isReady = true; if(docReadyProcId){ clearInterval(docReadyProcId); } if(Ext.isGecko || Ext.isOpera) { document.removeEventListener("DOMContentLoaded", fireDocReady, false); } if(Ext.isIE){ var defer = document.getElementById("ie-deferred-loader"); if(defer){ defer.onreadystatechange = null; defer.parentNode.removeChild(defer); } } if(docReadyEvent){ docReadyEvent.fire(); docReadyEvent.clearListeners(); } } };
var fireDocReady = function(){ if(!docReadyState){ docReadyState = true; //Ext.isReady = true; if(docReadyProcId){ clearInterval(docReadyProcId); docReadyProcId = null; } if(Ext.isGecko || Ext.isOpera) { document.removeEventListener("DOMContentLoaded", fireDocReady, false); } if(Ext.isIE){ var defer = document.getElementById("ie-deferred-loader"); if(defer){ defer.onreadystatechange = null; defer.parentNode.removeChild(defer); } } if(docReadyEvent && !Ext.isReady){ Ext.isReady = true; docReadyEvent.fire(); docReadyEvent.clearListeners(); } } };
/** * Fires when the document is ready (before onload and before images are loaded). Can be * accessed shorthanded as Ext.onReady(). * @param {Function} fn The method the event invokes * @param {Object} scope (optional) An object that becomes the scope of the handler * @param {boolean} options (optional) An object containing standard {@link #addListener} options */ onDocumentReady : function(fn, scope, options){ if(docReadyState){ // if it already fired docReadyEvent.addListener(fn, scope, options); docReadyEvent.fire(); docReadyEvent.clearListeners(); return; } if(!docReadyEvent){ initDocReady(); } docReadyEvent.addListener(fn, scope, options); },
/** * Fires when the document is ready (before onload and before images are loaded). Can be * accessed shorthanded as Ext.onReady(). * @param {Function} fn The method the event invokes * @param {Object} scope (optional) An object that becomes the scope of the handler * @param {boolean} options (optional) An object containing standard {@link #addListener} options */ onDocumentReady : function(fn, scope, options){ if(docReadyState){ // if it already fired docReadyEvent.addListener(fn, scope, options); docReadyEvent.fire(); docReadyEvent.clearListeners(); return; } if(!docReadyEvent){ initDocReady(); } options = options || {}; if(!options.delay){ options.delay = 1; } docReadyEvent.addListener(fn, scope, options); },