我需要使用组合框中出现的第一个值
像这样直接使用值
xtype: 'combobox',
fieldLabel: 'Type',
name: 'type',
store: [
'Bike'
'Car',
'Truck'
],
value: 'Bike' // this value
这很容易,因为给出了第一个值,但我需要像下面这样动态的
xtype: 'combobox',
fieldLabel: 'Type',
name: 'type',
store: this.type,
// value
它从数据库中获取类型,因此我不知道组合框中的第一个值
最佳答案
您将需要使用商店的加载事件来对数据加载执行操作。之后你就可以使用ComboBox的
select method
设置值。
这是工作代码:
Ext.application({
name: 'Fiddle',
launch: function () {
var states = Ext.create('Ext.data.Store', {
fields: ['abbr', 'name'],
data: [{
"abbr": "AL",
"name": "Alabama"
}, {
"abbr": "AK",
"name": "Alaska"
}, {
"abbr": "AZ",
"name": "Arizona"
}]
});
Ext.create({
xtype: 'panel',
title: 'Parent Panel',
frame: true,
renderTo: Ext.getBody(),
height: 500,
width: 400,
layout: {
type: 'vbox',
align: 'stretch'
},
items: [{
xtype: 'combobox',
store: states,
displayField: 'name',
valueField: 'abbr',
listeners: {
afterrender: function(combo) {
combo.store.on('load', function(store, records) {
combo.select(records[0]);
console.log(combo, records);
});
combo.store.load();
}
}
}],
collapsible: true
});
}
});
这是工作 fiddle 链接: https://fiddle.sencha.com/#view/editor&fiddle/2kgg
关于arrays - 如何使用组合框的第一个存储值作为默认值EXTJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51857549/