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

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

问题描述

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

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

事情神奇地运作.现在我正在使用 ext-all.js,它缩小了约 1.3MB,这是非常大的,恕我直言……当他进行第二次检查时,事情会神奇地加载……但我认为这两个功能与它们不同定义表明,因为如果我放置另一个 $(document).ready 而不是 Ext.onReady() 行,事情又会破裂.我认为 Ext.onReady({});函数还有其他一些 $(document).ready() 没有的黑魔法,如果有人知道这种魔法是什么,我很感兴趣?

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.

感谢您阅读这篇文章.=)附:我使用 ExtJS 大约一天了,所以我对它很陌生.

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

推荐答案

不,它们不一样,第一个将在您的 jQuery 库加载时触发,Ext.onReady(.. 将在您的 ExtJS 库时触发已加载.

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() 与 $(document).ready()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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