目的:是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);
},