如何在ExtJS Combobox中获取所选displayField的值

Arg*_*ist 3 extjs extjs3

如何在ExtJS 3.4 ComboBox中获取所选displayField的值?getValue()返回valueField,但我需要其他的.

小智 17

combo.getValue() - > valueField
combo.getRawValue() - > displayField


vaj*_*mar 6

如果是这种情况,

displayField : 'countryName',
valueField  : 'countryId',
Run Code Online (Sandbox Code Playgroud)

然后跟随函数给出所需的displayFiled(存储中甚至超过1个字段,你也可以得到它们)

function getFieldValues(combo, nameIn, nameOut){
     try{
          var r = combo.getStore().find(nameIn,combo.getValue());
          return combo.getStore().getAt(r).get(nameOut);
     }
     catch(err){
          return'error';
     }
}
Run Code Online (Sandbox Code Playgroud)

获取显示字段或存储中的任何其他字段的方式:

var item = getFieldValues(Ext.getCmp('combo'), 'countryId', 'countryName');
Run Code Online (Sandbox Code Playgroud)