Ext.onReady() vs $(document).ready()

后端 未结 3 2275
梦如初夏
梦如初夏 2021-02-15 11:45

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

3条回答
  •  盖世英雄少女心
    2021-02-15 12:35

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

提交回复
热议问题