天天看點

關于Extjs4.2的一些BUG

手頭上的一個項目用到Extjs4.2架構,使用過程中發現這個版本的Extjs還是存在挺多bug的。我遇到的bug中,有一些原因不詳,雖然通過修正ext-all.js源碼能解決,但不清楚根本原因,故不在此處提出。下面是我能确認的幾個bug:
           

1、Ext.data.Store配置autoLoad失效問題

代碼如下,定義了如下全局變量store_UserInfo,在js加載的時候store_UserInfo竟然觸發了beforeload事件,說明這個store在建立的時候自動調了一次load()方法。

var userInfo_Data = {"count":,"list":[]};
var store_UserInfo = Ext.create('Ext.data.Store', {
    model : 'model_userinfo',
    pageSize : ,
    autoLoad : false, //此處配了autoLoad為false
    data : userInfo_Data,//此處指定了data
    proxy : {
        type : 'memory',
        reader : {
            type : 'json',
            root : 'list',
            totalProperty: 'count',
        }
    },
    listeners : {
        beforeload:function(obj, opt){
            //store_UserInfo建立後自動地跳到這裡
            loadUserInfo(opt.start, opt.limit, userInfo_query);
        }
    }
});
           

我查了Extjs4.2的開發文檔,如下圖。文檔是這樣說的:如果沒有指定data,且autoLoad為true或一個Object對象,那麼store會在建立後自動調用load方法

關于Extjs4.2的一些BUG

奇怪的是我指定了data,且autoLoad為false,store還是自動調了load()方法。我調試了一下,發現無論autoLoad設為true、設為false、或是預設,store在建立後都會自動調用load()方法,也就是說autoLoad失效了。

我查了ext-all-debug.js源碼,找到定義Ext.data.Store的代碼段,store的construtor構造函數裡有一段代碼,如下圖

關于Extjs4.2的一些BUG

發現,如果data設了值且proxy配了Ext.data.proxy.Memory類型的proxy,不管autoLoad是什麼,store都會調read()的方法加載資料,是以觸發了beforeload事件。是以,如果要想在store配了data和memory型的proxy時,控制store是否自動加載資料,做如下修改

proxy = me.proxy;
        data = me.inlineData;
        if (data) {
            if (proxy instanceof Ext.data.proxy.Memory) {
                proxy.data = data;

                //autoLoad : false 失效修正
                if(me.autoLoad){
                    me.read();
                }

               //me.read(); //修正前
            } else {
                me.add.apply(me, data);
            }

            me.sort();
            delete me.inlineData;
        } else if (me.autoLoad) {
            Ext.defer(me.load, , me, [typeof me.autoLoad === 'object' ? me.autoLoad: undefined]);


        }
           

修正後,autoLoad就生效了,預設情況下不會自動load。

2、Ext.grid.column.Action标題不能顯示的問題

在指定标題内容時,我用text指定Ext.grid.column.Action的标題,但是确顯示為空。代碼如下:

關于Extjs4.2的一些BUG

檢視ext-all.js,發現Ext.grid.column.Action 與 Ext.grid.column.Column不一樣,後者是通過配置text屬性來指定标題内容,Ext.grid.column.Action是通過配置header屬性來指定。

讓人困惑的是Extjs4.2的文檔中Ext.grid.column.Action也是通過text屬性來指定标題,且沒有header屬性。

關于Extjs4.2的一些BUG

把Ext.grid.column.Action的text改為header即能正常顯示标題。

繼續閱讀