Принятое в настоящее время решение отлично работает, но если кому-то нужен ComboBox, который также обрабатывает ввод с клавиатуры, как обычный блок выбора HTML (например, каждый раз, когда вы нажимаете «P», выбирается следующий элемент в списке, начинающийся с «P»). ), может быть полезно следующее:
{
xtype: 'combo',
fieldLabel: 'Price',
name: 'price',
hiddenName: 'my_dropdown',
autoSelect: false,
allowBlank: false,
editable: false,
triggerAction: 'all',
typeAhead: true,
width:120,
listWidth: 120,
enableKeyEvents: true,
mode: 'local',
store: [
['val1', 'Appaloosa'],
['val2', 'Arabian'],
['val3', 'Clydesdale'],
['val4', 'Paint'],
['val5', 'Palamino'],
['val6', 'Quarterhorse'],
],
listeners: {
keypress: function(comboBoxObj, keyEventObj) {
// Ext.Store names anonymous fields (like in array above) "field1", "field2", etc.
var valueFieldName = "field1";
var displayFieldName = "field2";
// Which drop-down item is already selected (if any)?
var selectedIndices = this.view.getSelectedIndexes();
var currentSelectedIndex = (selectedIndices.length > 0) ? selectedIndices[0] : null;
// Prepare the search criteria we'll use to query the data store
var typedChar = String.fromCharCode(keyEventObj.getCharCode());
var startIndex = (currentSelectedIndex == null) ? 0 : ++currentSelectedIndex;
var matchIndex = this.store.find(displayFieldName, typedChar, startIndex, false);
if( matchIndex >= 0 ) {
this.select(matchIndex);
} else if (matchIndex == -1 && startIndex > 0) {
// If nothing matched but we didn't start the search at the beginning of the list
// (because the user already had somethign selected), search again from beginning.
matchIndex = this.store.find(displayFieldName, typedChar, 0, false);
if( matchIndex >= 0 ) {
this.select(matchIndex);
}
}
if( matchIndex >= 0 ) {
var record = this.store.getAt(matchIndex);
this.setValue(record.get(valueFieldName));
}
}
}
}