[英]how to get the value on extjs combo box?
我有一个组合框的以下代码,我如何获得在组合框中选择的值并将该值加载到变量中,并在以后使用它。
谢谢
Ext.define('Column', {
extend: 'Ext.data.Model',
fields: ['data1', 'Data2']
});
var store = Ext.create('Ext.data.Store', {
model: 'Column',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/data.xml',
reader: {
type: 'xml',
record: 'result'
}
}
});
var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
store: store,
displayField: 'data1',
valueField: 'data1',
width: 250,
labelWidth: 120,
fieldLabel: 'select a value',
renderTo: 'simpleCombo',
queryMode: 'local',
typeAhead: true
});
只需使用select事件即可
var simpleCombo = Ext.create('Ext.form.field.ComboBox', {
store: store,
displayField: 'data1',
valueField: 'data1' ,
width: 250,
labelWidth: 120,
fieldLabel: 'select a value',
renderTo: 'simpleCombo',
queryMode: 'local',
typeAhead: true,
listeners: {
select: function(combo, records) {
// note that records are a array of records to be prepared for multiselection
// therefore use records[0] to access the selected record
}
});
评论中的其他内容:
看一下组合框的multiSelect属性。 您将获得由定义的分隔符分隔的所有值,并且select事件将为您提供包含多个记录的记录数组。 请注意,getValue()仅为您提供已定义的displayField,它是一个字符串而不是记录本身。 因此,使用iComboValue [0]为您提供第一个字符。 应始终使用所选事件访问所选记录。 但是您可以将它们存储在一个数组中供以后使用,并使用任何新的选择覆盖它。
您还可以使用:
var iComboValue = simpleCombo.getValue();
也许你应该试试这个
// to get the combobox selected item outside the combo listener
simpleCombo.on('change', function (combo, record, index) {
alert(record); // to get the selected item
console.log(record); // to get the selected item
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.