denverj 发表于 2013-2-7 00:03:22

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);      },

修改之后,问题解决。
IE版本:IE8
Ext版本:Ext2.0 Beta1

官方原文地址:http://www.sencha.com/forum/showthread.php?43246-2.2-FIXED-Ext.onReady-and-onLoad
页: [1]
查看完整版本: Ext 2-iframe bug