Reputation: 3520
I am totally new to Extjs, Following is part of structure of my app
View - contain combobox
xtype: 'combobox',
itemId: 'myCombo',
fieldLabel: 'myLabel',
queryMode: 'local',
store: Ext.create('Ext.data.ArrayStore', {
fields: [{
name: 'key1'
}, {
name: 'key2'
}],
storeId: 'myStore',
autoLoad: false
}),
displayField: 'key1',
valueField: 'key2',
Controller - Contain reference to combobox
Ext.define('MyApp.controller.myController', {
extend: 'Ext.app.Controller',
views: ['MyApp.view.MyView'],
refs: [{
ref: 'myComboRef',
selector: '#myCombo'
}],
this.control({
'#myCombo': {
change: this.getData
}),
.
.
.
getData: function(currFeild, newValue, oldValue, eOpts){
// I can get "valueField" of myCombo by
var valueFieldData = this.getMyComboRef().valueField;
// I want to change "valueField" to "key3"
// ????????
});
So can anybody please tell me, how can I set new valueField for "myCombo" ?
I already visited this link. But, it didn't helped much
Upvotes: 0
Views: 2215
Reputation: 2063
I dont think it is a good solution to change the valueField
of a combo. Though i can do this via comob.valueField = 'newValueField';
e.g. in your change event handler. Though the getValue()
fn will show the value of your new value field only the next time you change a value. So i dont think this is a good approach.
The valueField
should be a field which identifies your records in the store and should usually not be changed. If you need to access other fields of your selected record you can get the selected record of the store and then access the field you want.
e.g. in your change event handler:
change: function(cmp, newValue){
var record = cmp.store.findRecord(cmp.valueField, newValue);
var field2Value = record.get('field2');
//do something with your field2Vlaue...
}
I have also made a fiddle for you so you can see this example in live action. https://fiddle.sencha.com/#fiddle/jek
Upvotes: 1