2

可能重复:
Smartgwt 选择项键值问题

我正在使用 setEditorCustomizer 为 ListGrid 中的某些字段设置自定义编辑器,我的具体问题出在 SelectItem 上

像这样的东西:

grid.setEditorCustomizer(new ListGridEditorCustomizer() {
    public FormItem getEditor(ListGridEditorContext context) {
         SelectItem selectItem = new SelectItem();
         LinkedHashMap<String, String> valuesMap = new LinkedHashMap<String, String>();
         valuesMap.put("0","some text");
         valuesMap.put("1","other text");
         selectItem.setValueMap(valuesMap);
    }
}

请注意,我没有为每一行创建选择项。

编辑行时一切正常,我在下拉列表中看到“一些文本”和“其他文本”,但是当我不编辑值时,我看到的是相应的键而不是值。

我已经搜索了 javadoc 但找不到任何东西,如果有什么不明确的,请询问,我会添加。

4

2 回答 2

0

您需要在 SelectItem 也出现的 ListGridField 上设置值映射()(具有相同的值映射)。

于 2012-08-21T19:31:08.923 回答
0

最终找到了一个解决方案,DataSource并将其设置在 optionDataSource 的 optionDataSource 中,SelectItem并将 displayField 和 valueField 设置为相应的字段。

然后,当该字段未被编辑时,ListGridField我设置了一个CellFormatter返回正确数据的自定义(这也涉及为其他值返回正确的数据)。

我很确定可能有一种更简单的方法,但是这种方法对我有用,所以我现在就这样吧。

于 2012-08-21T21:13:17.787 回答