Я столкнулся с этой проблемой пару раз. Единственный способ, которым я на самом деле решил эту проблему, - это вызвать setValue
в выпадающем списке после загрузки магазина, вы можете просто добавить слушателя в магазине, но это всегда казалось мне немного беспорядочным. У меня обычно есть автономный слушатель событий, подобный этому:
Store.on('load',function(store) {
Ext.getCmp('order-qty').setValue(store.getAt('0').get('qty'));
});
РЕДАКТИРОВАТЬ: 18 января 2012
ОК, как упомянуто здесь, является полным рабочим примером ComboBox с установленным значением по умолчанию. Это сделано с использованием ExtJS 4.02, должно работать нормально с 4.07, хотя, не уверен насчет 4.1.
Убедитесь, что вы указали правильный путь к extjs в ссылках (см. Скобки в верхней части html), в противном случае просто поместите и combo-example, и data.json на один и тот же уровень каталога, и они должны нормально работать:
data.json:
[
{"value":1,"name":"Option 1"},
{"value":2,"name":"Option 2"},
{"value":3,"name":"Option 3"}
]
комбо-example.html:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Combo Box Example</title>
<link rel="stylesheet" type="text/css" href="[your extjs path]/resources/css/ext-all.css">
<script type="text/javascript" src="[your extjs path]/ext-all.js"></script>
<script type="text/javascript" >
Ext.onReady(function() {
// the datastore
var myStore = new Ext.data.Store({
fields: ['value', 'name'],
proxy: {
type: 'ajax',
url : 'data.json',
reader: {
type: 'json'
}
},
autoLoad: true
});
// a window to hold the combobox inside of a form
myWindow = Ext.create('Ext.Window', {
title: 'A Simple Window',
width: 300,
constrain: true,
modal: true,
layout: 'fit',
items: [{
// the form to hold the combobox
xtype: 'form',
border: false,
fieldDefaults: {
labelWidth: 75
},
bodyPadding: '15 10 10 10',
items: [{
// the combobox
xtype: 'combo',
id: 'myCombo',
fieldLabel: 'A Label',
valueField: 'value',
displayField: 'name',
store: myStore,
//queryMode: 'local',
typeAhead: true,
forceSelection: true,
allowBlank: false,
anchor: '100%'
},{
// shows the selected value when pressed
xtype: 'button',
margin: '10 0 0 100',
text: 'OK',
handler: function() {
alert('Name: ' + Ext.getCmp('myCombo').getRawValue() +
'\nValue: ' + Ext.getCmp('myCombo').value);
}
}]
}]
});
// show the window
myWindow.show();
// function to give the combobox a default value
myStore.on('load',function(store) {
Ext.getCmp('myCombo').setValue(store.getAt('0').get('value'));
});
});
</script>
</head>
<body>
</body>
</html>