2

嗨,我正在尝试使用SmartGWT

我有数组列表

ArrayList<FileDocument> documentsArrayList = new ArrayList<FileDocument>();

// 所有的值都在documentsArrayList中

和一张桌子

private ListGrid getDocumentTable() {
        if (documentTable == null) {
            documentTable = new ListGrid();
            documentTable.setSize("644px", "379px");
            documentTable.setCanResizeFields(true);

            documentTable.setFields(getStatus(),getIcon(),getName(),getSize(),getModifiedby(),getModifiedDate());
        }
        return documentTable;
    }

网格的字段就像

public ListGridField getName() {
        if (name == null) {
            name = new ListGridField("name","Name");
        }
        return name;
    }

我想将值放入数组列表值到表中。

documentTable.setData(一些列表网格记录);

如何转换ArrayList以便ListGridRecord 我可以设置数据。

4

2 回答 2

3

您需要创建一个方法,将您ArrayList作为输入并返回 ListGridRecord 数组,然后可以使用listGrid.setData(ListGridRecord[] records);

开场示例:

 listGrid.setData(getListridRecords(employees)); // set records here 

 private void getListGridRecords(ArrayList employees) {
      ListGridRecords records[]=null;
      if(employees!=null){
       records = new ListGridRecord[employees.size()];
       for(int cntr=;cntr<employees.size();cntr++){
        ListGridRecord record = new ListGridRecord();   
        Employee emp = employees.get(cntr);
        record.setAttribute("name",emp.getName()); //your ListGridField 's name
        record.setAttribute("status",emp.getStatus()); //your ListGridField 's name
        //.. more goes here
        records[cntr] = record;
      }

   }
   return records;
}

另一种方式可能是这样

于 2012-04-30T10:31:42.533 回答
0

你也可以使用类

可以将 Array 列表转换为可以添加到 ListGridField 的 setData 方法的 recordList。下面是实现的代码片段。

`RecordList recordList = new RecordList();
 for(DocumentsArrayList documentsArray: documentsArrayList)
 {
  Record record = new Record();
  record.setAttribute("Name", getName());
  record.setAttribute("size", getSize());
  record.setAttribute("user", getuser());
  recordList.add(record);
 }          
 documentTable.setData(recordList);
 }

` 所有的属性名都应该和 POJO 中的值匹配,这样才能直接使用值对象。

于 2013-12-26T21:10:13.197 回答