简体   繁体   English

extjs组合显示值

[英]extjs combo display value

In ext js, when I have a combo, there is display value and value( which is sent to server). 在ext js中,当我有一个组合时,有显示值和值(发送到服务器)。 I do not need displayValue to send to server, but I need to capture it on the page and display an alert. 我不需要displayValue发送到服务器,但是我需要在页面上捕获它并显示警报。 What is the eextjs method of doing this? 这样做的eextjs方法是什么? combo.getValue() will return the underlying value...and I do not see any combo.getDisplay() combo.getValue()将返回基础值...并且我看不到任何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. 我希望在onselect或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. 如果将组合框上的valueField属性设置为希望在警报中显示的值,它将正常工作。

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. getRawValue():String返回组合的原始String值,而不执行任何规范化,转换或验证。 Gets the current value of the input element if the field has been rendered, ignoring the value if it is the emptyText. 如果字段已渲染,则获取输入元素的当前值;如果该字段为emptyText,则忽略该值。

combo.getRawValue(); combo.getRawValue();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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