1
在我的應用程序中,所有組件的標題/文本都是基於應用程序啓動之前加載的商店本地化的。在應用程序,我有按鈕,改變商店網址,並重新加載商店切換語言。問題是所有的類都已經被加載,所以組件以先前的語言環境呈現。這裏是按鈕的代碼:ExtJs 4重新加載應用程序
tbar: [{
xtype: 'button',
id: 'btn-test',
text: 'xxx',
handler: function() {
lang = 'en';
i18n.getBundlestore().load({url:'/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties'});
//bun = Ext.create('I18N.ResourceBundle');
Ext.getCmp('mainview').destroy();
Ext.create('Ext.container.Viewport', {
id: 'mainview',
layout: 'border',
items: [
{
xtype: 'gsip_mainpanel',
region: 'center',
items: [{
xtype: 'gsip_categoriestabpanel'
}]
}
]
完全相同的視口創建是在我的Application.js。 lang和i18n是全局變量。舊的視口被破壞,新的被創建,但如何強制重新加載classess。我不想使用window.location。
代碼更新:
handler: function() {
lang = 'en';
Ext.getCmp('mainview').destroy();
i18n.getBundlestore().load({url:'/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties',
callback: function() {
Ext.create('Ext.container.Viewport', {
id: 'mainview',
layout: 'border',
items: [
{
xtype: 'gsip_mainpanel',
region: 'center',
items: [{
xtype: 'gsip_categoriestabpanel'
}]
}
]
});
}
});
}
CategoriesTabPanel:
Ext.define('GSIP.view.CategoriesTabPanel' ,{
extend: 'Ext.tab.Panel',
alias : 'widget.gsip_categoriestabpanel',
layout: 'fit',
items: [{
xtype: 'gsip_planytabpanel',
title: i18n.getMsg('key-1')
},{
xtype: 'gsip_adresytabpanel',
title: i18n.getMsg('key-2')
}],
initComponent: function() {
this.callParent(arguments);
}
});
和資源包化(i18n變量是這個類的一個實例):
Ext.define('I18N.ResourceModel',{
extend: 'Ext.data.Model',
fields: ['key', 'value']
});
Ext.define('I18N.ResourceStore',{
extend: 'GSIP.core.RegisteredStore',
model: 'I18N.ResourceModel',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/GSIP/resources/gsip/i18n/bundle-' + lang + '.properties',
reader: {
type: 'json',
root: 'pl',
successProperty: 'success'
}
}
});
Ext.define('I18N.ResourceBundle' ,{
config: {
bundlestore: Ext.create('I18N.ResourceStore'),
},
constructor: function(config) {
this.initConfig(config);
return this;
},
getMsg: function(key) {
return this.bundlestore.getAt(this.bundlestore.findExact('key', key)).get('value');
}
},function(){
//callback function, called before store load :(
}
);
雖然可能沒有解決您的問題,但您的代碼存在問題:商店負載是異步的,所以很有可能在商店加載之前創建新的視口。你應該真的銷燬舊視圖並在傳遞給load方法的回調中創建新視圖。 – Izhaki 2012-07-10 08:44:05
你是對的,應該在回調函數中重新創建視口。我更新了代碼。它仍然不能解決我的問題。 – patryks 2012-07-10 09:51:10
您能否提供'gsip_categoriestabpanel'的代碼?我懷疑你要麼在對象中引用配置。 – Izhaki 2012-07-10 10:57:39