我想在ExtJS中实现以下组合框。问题是,如何默认选择第三个选项?
<select name="meter_payment_option" onChange="smart_meter(this.value)">
<option value="1">All Up-Front</option>
<option value="2">Reduced Up-Front</option>
<option value="3" selected="selected">No Up-Front</option>
</select>
我目前拥有的是:
var meter_payment_option_values = new Ext.data.SimpleStore({
fields: ['id', 'value'],
data: [
['1', 'All Up-Front'],
['2', 'Reduced Up-Front'],
['3', 'No Up-Front']]
});
var smart_meter_term = new Ext.form.ComboBox({
name: 'smart_meter_term',
editable: false,
typeAhead: false,
allowblank: false,
triggerAction: 'all',
hiddenName: 'my_dropdown',
fieldLabel: 'SmartM.T',
store: meter_payment_option_values,
displayField: 'value',
valueField: 'id',
mode: 'local'
});
如何默认选择第3个选项(No Up-Front)?
答案 0 :(得分:10)
您需要将value
配置选项设置为默认值的ID,例如:
var smart_meter_term = new Ext.form.ComboBox({
name:'smart_meter_term' ,
editable: false,
typeAhead: false,
allowblank:false ,
triggerAction: 'all',
hiddenName: 'my_dropdown',
fieldLabel:'SmartM.T',
store:meter_payment_option_values,
displayField:'value',
valueField:'id',
mode:'local',
// default value is 3 (No Up-Front)
value: 3
});
http://www.sencha.com/deploy/dev/docs/index.html?class=Ext.form.ComboBox