简体   繁体   English

如何在extjs组合框中按Enter获得所选结果的值

[英]How to get the value of the selected result on pressing enter in extjs combobox

I have a combobox and i navigate through the search results using the UP/DOWN arrow keys and when i press enter on a particular result,i load a different view and i also need the value(against the valuefield)of the selected result. 我有一个组合框,我使用向上/向下箭头键在搜索结果中导航,当我在特定结果上按Enter键时,我将加载另一个视图,并且我还需要所选结果的值(与valuefield相对)。

I have used specialkey event and if (e.getKey() == e.ENTER) then i do a getValue() and then i load the view. 我已经使用了specialkey事件,并且if (e.getKey() == e.ENTER)然后执行getValue(),然后加载视图。 But on getValue(), i get the raw value ie the string that i displayed and not the value against the valuefield(i have displayField:'Name' and valueField:'id'). 但是在getValue()上,我得到了原始值,即我显示的字符串,而不是针对valuefield的值(我有displayField:'Name'和valueField:'id')。

I also tried firing a select event and in its listener i do a combo.getValue(), still i get the raw value and not the value against the valuefield. 我还尝试触发一个select事件,并在其侦听器中执行combo.getValue(),但仍然得到原始值,而不是针对valuefield的值。 I need the id because i may have 2 or more search results with the same name but each one will have a unique id. 我需要ID,因为我可能有2个或多个具有相同名称的搜索结果,但每个搜索结果都有一个唯一的ID。

Is there a way i can get the value ? 我有办法获得价值吗?

the combobox hooks into 2 events of the picker which should be interesting for you: 组合框会关联到选择器的2个事件,这对您来说应该很有趣:

me.mon(picker, {
    itemclick: me.onItemClick,
});

me.mon(picker.getSelectionModel(), {
    selectionchange: me.onListSelectionChange,
});

source: http://docs.sencha.com/extjs/4.2.2/source/ComboBox.html#Ext-form-field-ComboBox 来源: http : //docs.sencha.com/extjs/4.2.2/source/ComboBox.html#Ext-form-field-ComboBox

you need to hook into this events and then you should have your value 您需要了解这些事件,然后您就应该拥有自己的价值

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

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