简体   繁体   English

选择GWT ComboBox项将显示值而不是文本

[英]Selecting a GWT ComboBox item displays the value and not the text

Using Java and GWT, I have a contentGrid with a custom column definition and a content Store. 使用Java和GWT,我有一个带有自定义列定义和内容存储的contentGrid。

One of the columns of the grid needs to show a combo box with several options. 网格的一列需要显示一个带有多个选项的组合框。 The combo box and its contents are defined as such: 组合框及其内容的定义如下:

ComboBox comboBox = new ComboBox();
SimpleStore comboBoxStore = new SimpleStore( new String[]{"text","id"}, new String[][] { new String[] {"John", "Mike"} , new String[] {"1","2"} } );
comboBoxStore.load();
comboBox.setDisplayField( "text" );
comboBox.setValueField("id" );
comboBox.setStore( comboBoxStore );
comboBox.setForceSelection( true );
comboBox.setEditable( false );

nameColumnConfig.setEditor(new GridEditor( comboBox ));

The grid then displays correctly, double-clicking the nameColumnConfig displays the combo box with the correct elements "John" and "Mike". 然后,网格将正确显示,双击nameColumnConfig会显示带有正确元素“ John”和“ Mike”的组合框。

But when I click on one of those options and click away for the grid so it "updates" itself, the combobox displays the id of the selected option and not it's displayField. 但是,当我单击这些选项之一并单击以离开网格以使其自身“更新”时,组合框将显示所选选项的ID,而不是displayField。

I've been looking for a solution for some time, and I haven't found anything that could remotely let me know how to solve it or what's the cause. 我一直在寻找一种解决方案,但没有发现任何可以让我知道如何解决它或原因的东西。

I would greatly appreciate any help or insight in this issue. 对于此问题的任何帮助或见解,我将不胜感激。

Thanks. 谢谢。

Instead of putting like this--- 而不是像这样-

comboBox.setDisplayField( "text" ); 
comboBox.setValueField("id" ); 

You have to do like 你必须喜欢

comboBox.setDisplayField( "text" ); 
comboBox.setValueField("text" ); 

sure , you will get an answer. 当然,您会得到答案。

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

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