How to get dispayfield in extjs combo?

In the extjs drop-down list, we have valueField, displayField . There is one getValue(). But no getDisaplay(). So how to grab the dispay field name?

+6
source share
4 answers

Use the value to get the record from the repository and get the displayed value from it.

Thus, you can use this code, but you can replace some of the variables for known values ​​to make it more readable:

 getComboDisplay = function(combo) { var value = combo.getValue(); var valueField = combo.valueField; var record; combo.getStore().each(function(r){ if(r.data[valueField] == value){ record = r; return false; } }); return record ? record.get(combo.displayField) : null; } 
+1
source

What about the getRawValue method?

 Ext.getCmp('combo').getRawValue(); 
+10
source

is an easy solution that works for me:

 comboselect: function (combo,record) { alert(combo.rawValue); } 

hope you help

+1
source

ExtJS 4 has a built-in findRecord() method that does the search suggested by BigSean above, so you don't need to write all this code:

 Ext.override(Ext.form.field.ComboBox, { getDisplayedValue: function() { // getDisplayValue() already exists but is a private method var me = this, value = me.value, record = null; if(value) { record = me.getStore().findRecord(me.valueField, value); } if(record) { return record.get(me.displayField); } return null; } }); 
0
source

Source: https://habr.com/ru/post/886012/


All Articles