[英]how to get the value on extjs combo box?
I have a following code for combo box, how can I get the value that is selected in the combobox and load that value into a variable, and use it later. 我有一个组合框的以下代码,我如何获得在组合框中选择的值并将该值加载到变量中,并在以后使用它。
Thank you 谢谢
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
});
Simply use the select event 只需使用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
}
});
Additional content from the comments: 评论中的其他内容:
Take a look at the multiSelect property of the combobox. 看一下组合框的multiSelect属性。 You get all values separated by a defined delimiter and the select event will give you a records array with more that one record.
您将获得由定义的分隔符分隔的所有值,并且select事件将为您提供包含多个记录的记录数组。 Note the that getValue() only give you the defined displayField which is a string and not the record itself.
请注意,getValue()仅为您提供已定义的displayField,它是一个字符串而不是记录本身。 So using iComboValue[0] gives you the first character.
因此,使用iComboValue [0]为您提供第一个字符。 The selected records should always be accessed using the selected event.
应始终使用所选事件访问所选记录。 But you may store them in a array for later use and overwrite it with any new select.
但是您可以将它们存储在一个数组中供以后使用,并使用任何新的选择覆盖它。
您还可以使用:
var iComboValue = simpleCombo.getValue();
may be you should try this 也许你应该试试这个
// 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.