How to select combobox value in ExtJs?

I am trying to just select an item from the drop-down list after loading it into the repository. This does not work:

Ext.getCmp('ddlModel').setValue(aircraftStore.getAt(0).data.ModelTypeCode); 

This throws an exception:

 Ext.getCmp('ddlModel').selectByValue(aircraftStore.getAt(0).data.ModelTypeCode); 

Here is the exception: 'this.view' is null or not an object

Does anyone know how to do this in ExtJs?

+4
source share
4 answers

I created a function to set the value of a combo box in ExtJs:

 function ComboSetter(comboBox, value) { var store = comboBox.store; var valueField = comboBox.valueField; var displayField = comboBox.displayField; var recordNumber = store.findExact(valueField, value, 0); if (recordNumber == -1) return -1; var displayValue = store.getAt(recordNumber).data[displayField]; comboBox.setValue(value); comboBox.setRawValue(displayValue); comboBox.selectedIndex = recordNumber; return recordNumber; } 
+9
source

Ext.getCmp('ddlModel').select(aircraftStore.getAt(0));

+2
source

In many cases, you may need to install combobox for a specific index. In ExtJs 4.2 you can do it like this:

 function setIndex(combobox, value) { combobox.setValue(combobox.store.data.items[value].data.field1); } 
0
source

in my case, I needed to get the combobox id, then compare to if, and thus pass the second window, use this method, and it worked.

 var ValorSeleccionado = Ext.getCmp('cmb_tipoderol_usr').getValue(); // 'cmb_tipoderol_usr' is the id of the combobox. 

then compare with action

 if (ValorSeleccionado == 1 ) { Do Action } 
0
source

All Articles