SmartGWT中ListGrid中的setData
您好,我正在尝试使用SmartGWT中ListGrid中的setData,gwt,smartgwt,gwt2,listgrid,Gwt,Smartgwt,Gwt2,Listgrid,您好,我正在尝试使用SmartGWT 我有Arraylist ArrayList<FileDocument> documentsArrayList = new ArrayList<FileDocument>(); 网格的字段类似于 public ListGridField getName() { if (name == null) { name = new ListGridField("name","Name");
SmartGWT
我有Arraylist
ArrayList<FileDocument> documentsArrayList = new ArrayList<FileDocument>();
网格的字段类似于
public ListGridField getName() {
if (name == null) {
name = new ListGridField("name","Name");
}
return name;
}
我想把值放到数组中,把值放到表中
documentTable.setData(一些列表网格记录)
如何在ListGridRecord
因此,我可以设置数据。您需要创建一个方法,该方法将接受您的
ArrayList
作为输入,并返回一个ListGridRecord数组,然后可以使用listGrid.setData(ListGridRecord[]记录)设置该数组代码>
启动示例:
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;
}
listGrid.setData(getListridRecords(employees));//在这里创纪录
私有void getListGridRecords(ArrayList员工){
ListGridRecords记录[]=null;
如果(员工!=null){
records=新ListGridRecord[employees.size()];
对于(int cntr=;cntr,您还可以使用
数组列表可以转换为recordList,该recordList可以添加到ListGridField的setData方法中。
下面是实现的代码片段
`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中的值匹配,以便可以直接使用值对象。您能帮我解决这个问题吗:我无法在表中添加此记录。我已添加了打印堆栈
`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);
}