extjs提示框MessageBox漢化bug

來源:互聯網
上載者:User

目的:是Ext的提示框使用中文按鈕

現象:當使用者載入ext中文包,但是Ext.MessageBox ,Ext.Msg的時候依然是英文的button


源碼: Ext.MessageBox = Ext.Msg = new this();


    if(Ext.MessageBox){
        Ext.window.MessageBox.prototype.buttonText = {
            ok: "確定",
            cancel: "取消",
            yes: "是",
            no: "否"
        };
    }

結論:綜合分析後就不難得出,因為Ext.MessageBox = Ext.Msg全域對象已經在匯入中文包之前已就已經產生了,所以後來的中文包就無法作用了(這裡做一個猜測,沒有去驗證有興趣的人可以自己驗證了,雖然原始碼是修改了該類的prototype對象,但是執行個體化的對象不是直接調用該值去產生快顯視窗,而是執行個體化對象的時候已經把該buttonText參數閉包給某些方法了)
解決方案:

if(Ext.MessageBox){
        Ext.window.MessageBox.prototype.buttonText = {
            ok: "確定",
            cancel: "取消",
            yes: "是",
            no: "否"
        };
        Ext.MessageBox = Ext.Msg = new Ext.window.MessageBox();
    }

只需要在中文包裡重建下該對象即可

例如:

My Code:

[javascript] 
onLogout: function () { 
   //為了提示中文,只能把源碼更改,因為ext的漢化包有個bug,直接調用不好 
     Ext.window.MessageBox.prototype.buttonText = { 
                ok: "確定", 
                cancel: "取消", 
                yes: "是", 
                no: "否" 
     }; 
     Ext.MessageBox = Ext.Msg = new Ext.window.MessageBox(); 
     Ext.Msg.confirm('系統提示','您真的要退出系統?',function(btn){ 
            if(btn=='yes'){ 
                 window.location.href="/gwater/common/userlogin.action";                     
            }else{ 
               
            } 
             
    },this); 
       
   }, 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.