gwt suggestionBox如何获取文本,值对中 [英] gwt suggestionBox how to get text,value pairs in it
问题描述
我需要一个autosuggest组合框的一个模糊的字符串列表。但everey字符串有一个唯一的id。这个id需要知道用户选择了什么(发送id回到服务器并做一些事情)。
i need a autosuggest combobox for an ambiguous list of strings. but everey string has an unique id. this id is needed to know what the user has selected (send id back to server and do something with it).
如何使用gwt的auto-suggest- comboBoxsuggestionBox。有没有办法得到id->名称对的列表(像listBox.addItem(String name,String value))到suggestionBox?
可能是通过覆盖建议Oracle? (如何获取所选名称的所选ID?)
how to implement this with the gwt's auto-suggest-comboBox "suggestionBox". Is there a way to get an List of id->name pairs (like with listBox.addItem(String name, String value)) into the suggestionBox? probably by overwriting suggestionOracle? (how to get the selected id of the selected name?)
或者这个用例更好地由另一个gwt小部件实现?
or is this usecase better be implemented by another gwt widget?
thx提前
推荐答案
是的,你想子类SuggestionOracle。
Yep, you want to subclass SuggestionOracle. You also want to subclass Suggestion, to something that can hold the id you need.
public class StringWithIdSuggestion implements Suggestion {
Long id;
String string;
@Override public String getDisplayString(){
return string;
}
@Override public String getReplacementString() {
return string;
}
public Long getId() {
return id;
}
}
然后你的建议oracle将给予StringWithIdSuggestion实例可以投射访问getId();
Then your suggestion oracle will give StringWithIdSuggestion instances, which you can cast for access to getId();
这篇关于gwt suggestionBox如何获取文本,值对中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!