问题
In combo editor, after select a option, it display value even I set display Field. Once I click the combo editor, it will display displayField as well, but after select and click the others (It means mouse out) then the cell value changed to valueField.
my combo editor code,
{
xtype : 'combo',
editable : false,
triggerAction : 'all',
displayField : 'name',
valueField : 'id',
store : myStore
}
what I missed?
anyone know, please advice me~
Thanks!
[Edit]
I write test code in here :
http://jsfiddle.net/ilovekanon/NQXw9/
change name and click the others then the name will show ID, not name :(
回答1:
Your jsFiddle code dose not wrong.
displayField
in combo is mean that displayed data field name in combo.
It's not displayed value in grid.
grid display selected value, when selected option in combo.
if you want to display name
in combo's store, valueField
must is set 'name',
So, If you need to id in combo's store, You maybe set new hidden grid column. when change event trigger.
回答2:
You need to add a model
(or a model config) to the combo's store
, then call .setValue()
combo.store.add({id:3, name:'expert wanna-be'});
combo.setValue(3);
Example:
http://jsfiddle.net/y944g/
The model will be over-written when you load the combo's store (by clicking the trigger), so you don't have to worry about duplicates or anything.
来源:https://stackoverflow.com/questions/11728341/extjs4-how-to-set-displayfield-in-combo-editor