我有combobox,它代表从服务器端重新获取的登录类型。登录类型的翻译应该在客户端进行。
这是从服务器端返回的json示例:
[
{"valueField":"activeDirectory"},
{"valueField":"userpass"}
]
Combobox的定义如下:
Ext.create('Ext.form.ComboBox', {
fieldLabel : window._i18n['login.login-panel.logintype'],
itemId : 'logintype',
store : loginTypesStore,
name : 'loginType',
hiddenName: 'hiddenName',
displayField : 'localizedDisplayField',
valueField : 'valueField',
submitValue: true,
forceSelection: true,
editable : false,
allowBlank : false,
queryMode: 'remote'
})
和模型和商店定义为:
Ext.define('loginTypeModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'valueField' },
{
name: 'localizedDisplayField',
convert: function(value, record) {
return window._i18n['login.login-panel.logintypename.' + record.get('valueField')];
}
}
],
proxy: {
type: 'ajax',
url: 'Admin/LoginTypes',
reader: {
type: 'json'
}
}
});
var loginTypesStore = Ext.create('Ext.data.Store', {
autoLoad: false,
type: 'json',
model: 'loginTypeModel'
});
我为商店添加了加载侦听器,它应该将组合框值设置为收到的第一个项目:
loginTypesStore.on('load', function () {
var combo = Ext.getCmp('login-panel').getComponent('logintype');
console.log('combo.Value : [' + combo.getValue() + '] -> [' + loginTypesStore.data.first().data.valueField + ']');
combo.setValue(loginTypesStore.data.first().data.valueField); //loginTypesStore.data.first().data.valueField);
console.log('combo.Value = ' + combo.getValue());
});
但是,在控制台输出中,我可以看到:
combo.Value : [null] -> [activeDirectory]
combo.Value = Active Directory EN
"Active Directory EN"
是"activeDirectory"
密钥的英文翻译。
这怎么可能?
当我用这样的本地替换商店时:
var loginTypesStore = Ext.create('Ext.data.Store', {
fields: ['valueField', 'localizedDisplayField'],
data: [
{"valueField": "userpass", "localizedDisplayField": "Localized userpass"},
{"valueField": "activeDirectory", "localizedDisplayField": "Localized activeDirectory"}
]
});
一切正常,即在控制台我看到:
combo.Value : [null] -> [userpass]
combo.Value = userpass