【问题标题】:Duplicate DataSource field in use with SelectItem (smartGWT)与 SelectItem (smartGWT) 一起使用的重复数据源字段
【发布时间】:2012-09-30 17:26:19
【问题描述】:

我正在尝试在 SelectItem 组件中列出一个表。我为此目的使用 ListGrid 组件。代码如下:

    final ListGrid brandGrid = new ListGrid();

    ListGridField nameField = new ListGridField("name");
    ListGridField descriptionField = new ListGridField("description");
    ListGridField detailField = new ListGridField("detail");

    final SelectItem filterList = new SelectItem();
    filterList.setDisplayField("name");
    filterList.setValueField("description");
    filterList.setPickListWidth(400);


    filterList.setOptionDataSource(myDataSource);
    filterList.setPickListFields(nameField, descriptionField);
    filterList.setPickListProperties(brandGrid);
    filterList.setDefaultValue(record.getAttributeAsString("name"));
    filterList.setShowTitle(false);
    filterList.setStartRow(false);

以及myDataSource实例的DataSource代码(我在使用SelectItem filterList之前调用这个方法来初始化类属性DataSource myDataSource):

private DataSource getBrandData(List<BrandDB> result){
        DataSource ds = new DataSource();

        DataSourceTextField id = new DataSourceTextField();
        id.setName("idBrand");
        id.setPrimaryKey(true);

        DataSourceTextField name = new DataSourceTextField();
        name.setName("name");

        DataSourceTextField description = new DataSourceTextField();
        description.setName("description");

        ds.setFields(id, nazov, popis);

        ds.setClientOnly(true);
        for(int i = 0; i < result.size(); i++){
            Record rc = new Record();
            rc.setAttribute("idBrand", result.get(i).getIdBrand()+"");
            rc.setAttribute("name", result.get(i).getName());
            rc.setAttribute("description", result.get(i).getDescription());
            ds.addData(rc);
        }
        return ds;
    }

问题是我的数据源中的值description 在多个位置具有相同的值(这些值的 id 和名称不同)。我收到以下错误:

TMR0:WARN:fetchMissingValues:isc_SelectItem_1:Deriving valueMap for 'description' from dataSource based on displayField 'name'. This dataSource contains more than one record with description set to Not defined with differing name values. Derived valueMap is therefore unpredictable.

任何想法如何设置 SelectItem 以接受这些重复值?非常感谢您的回答。 :)

【问题讨论】:

    标签: java gwt datasource smartgwt


    【解决方案1】:

    问题解决了:

    错误位于这行代码中:

    filterList.setValueField("description");
    

    描述不是唯一的,因此它不能是 SelectItem 组件内的值字段。只需编辑这行代码如下:

    filterList.setValueField("idBrand");
    

    idBrand 是唯一的,因为它被定义为 DataSource 中的主键,因此 SelectItem 已经唯一标识了它的值字段并且可以进行过滤。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-29
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多