简体   繁体   中英

extjs combo display value

In ext js, when I have a combo, there is display value and value( which is sent to server). I do not need displayValue to send to server, but I need to capture it on the page and display an alert. What is the eextjs method of doing this? combo.getValue() will return the underlying value...and I do not see any combo.getDisplay()

EDIT: Just to clarify, I am looking to get the display value of the item that is selected by the user. I wish to show an alert on the onselect or on changeevent.

If you set the valueField property on the combo box to the value you wish to display in the alert that will work fine.

alert(combo.getValue());

If you want this value to be different from the value you submit to the server you will have to get the store from the combo box and find the corresponding record.

var store = combo.getStore();
var index = store.find('*YourFieldName*', combo.getValue());
if(index != -1)//the record has been found
  {
      var record = store.getAt(index);
      //you can then do what you like with the record.
  }
 combo.getStore().getById(combo.getValue()).raw.displayAttribute //Ext 4.x, 
 //displayAttribute: displayField or displayed attrib in store data for the combo

Let's assume that you have following in your combobox:

id: 'COMBOBOX_ID',
displayField: 'COMBOBOX_DIS_FIELD_NAME',
valueField: 'COMBOBOX_VAL_FIELD_NAME'

Then, you can do following:

var combo = Ext.getCmp('COMBOBOX_ID');
var comboStore = combo.getStore();
var index = comboStore.find('COMBOBOX_VAL_FIELD_NAME', combo.getValue());
if(index != -1)
{
  var selectedItemDisplayValue = combo.getStore().getAt(index).get('COMBOBOX_DIS_FIELD_NAME');
}

We can retreive the underlying store, then use our value as a key to get the display value.

Something like this (I haven't tested it):

var displayValue = combo.getStore()[combo.getValue()]

We can get the combo box display value something like this...

getRawValue( ) : String Returns the raw String value of the combo, without performing any normalization, conversion, or validation. Gets the current value of the input element if the field has been rendered, ignoring the value if it is the emptyText.

combo.getRawValue();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM