Ext.onReady()vs $(document).ready() [英] Ext.onReady() vs $(document).ready()

查看:143
本文介绍了Ext.onReady()vs $(document).ready()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么区别?我有$(document).ready函数,它应该检查extjs是否被加载,但是主要问题是extjs没有按时加载,并且$(document)中的内容.ready开始执行,extjs create函数产生主错误'无法在Ext.create(...,{..})上执行未定义的创建。线。如果我把这样的双重检查:

  $(document).ready(function(){
Ext.onReady (function(){
Ext.create('Ext.Button',{...});
});
});

事情神奇地工作。现在我使用的ext-all.js已经〜1.3MB最小化,这是非常大的imho ...和事情得到神奇的加载,而他做第二次检查...但我认为这2个功能是不一样的他们定义表明,因为如果我再放一个$(document).ready而不是Ext.onReady()行,那么事情再次破裂。我想Ext.onReady({});功能做一些其他的黑魔法,$(document).ready()不会,如果有人知道这是什么魔法,我有兴趣吗?



因为它工作,我不知道为什么会杀死我。感谢您阅读这篇文章。



=)
ps。我正在使用ExtJS大约一天,所以我很新。

解决方案

不,他们不一样,当您的jQuery库加载时,第一个将被执行,Ext.onReady(..将在您的ExtJS库加载时执行。



如果要组合它们可以这样做:

  var extReady = false; 
var jQueryReady = false;

var librariesReady = function(){
if(jQueryReady&& extReady){
//他们都准备好
}
};

$(document).ready(function(){
jQueryReady = true;
librariesReady();
});
Ext.onReady(function() b $ b extReady = true;
librariesReady();
});


Whats the difference? I have on $(document).ready function which should check if extjs is loaded but the main problem is extjs does not load on time and things inside $(document).ready starts to execute, extjs create function which produces the main error 'cannot execute create of undefined' on Ext.create("...", {..}); line. If i put double check like this:

$(document).ready(function() {
    Ext.onReady(function() {
        Ext.create('Ext.Button', {...});
    });
});

Things magically work. Now I'm using ext-all.js which has ~1.3MB minified which is pretty large imho...and things get magically loaded while he does the second check...but I think those 2 functions are not the same as they definitions suggest, because if I put another $(document).ready instead of Ext.onReady() line, things break again. I think Ext.onReady({}); function does some other black magic which $(document).ready() does not, and I'm interested if someone knows what is this kind of magic?

Because it work's and I don't know why which is killing me.

Thanks for reading the post. =) ps. I'm using ExtJS for about day so I'm pretty new to it.

解决方案

No they're not the same, the first one will proc when your jQuery library is loaded, the Ext.onReady(.. will proc when your ExtJS library is loaded.

If you want to combine them you could do something like this:

var extReady = false;
var jQueryReady = false;

var librariesReady = function () {
    if (jQueryReady && extReady) {
        //They're both ready
    }
};

$(document).ready(function () {
    jQueryReady = true;
    librariesReady();    
});
Ext.onReady(function () {
    extReady = true;
    librariesReady();
});

这篇关于Ext.onReady()vs $(document).ready()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆