[英]SmartGWT DataSource string XML
I am currently using a SmartGWT grid, that uses a DataSource object, which receives an xml file. 我目前正在使用SmartGWT网格,该网格使用DataSource对象,该对象接收xml文件。 All is well with this approach, but I want to know if I can just send a string with an xml structure.
一切都很好用这种方法,但我想知道我是否可以发送一个带有xml结构的字符串。 Something like the below:
像下面这样的东西:
String xml = "<listgrid><data><campo1></campo1>hola<campo2>mundo</campo2></data></listgrid>";
setData(xml);
This is pseudo-code, but it should give an idea to the reader. 这是伪代码,但它应该给读者一个想法。
I've searched and found no example that fulfills my requirements. 我搜索过,发现没有符合我要求的例子。
There is a better way. 有个更好的方法。 What you want to do is populate the dataSource dynamically.
您要做的是动态填充dataSource。
Here's an example: 这是一个例子:
public void onModuleLoad() {
DataSourceTextField continentField = new DataSourceTextField("continent");
continentField.setPrimaryKey(true);
DataSource dataSource = new DataSource();
dataSource.setClientOnly(true);
dataSource.setFields(continentField);
for (CountryRecord record : new CountryData().getNewRecords()) {
dataSource.addData(record);
}
ListGrid myGrid = new ListGrid();
myGrid.setWidth(200);
myGrid.setHeight(100);
myGrid.setDataSource(dataSource);
myGrid.fetchData();
myGrid.draw();
}
class CountryData {
public CountryRecord[] getNewRecords() {
return new CountryRecord[] {
new CountryRecord("North America"),
new CountryRecord("Asia") };
}
}
class CountryRecord extends ListGridRecord {
public CountryRecord(String continent) {
setContinent(continent);
}
public void setContinent(String continent) {
setAttribute("continent", continent);
}
public String getContinent() {
return getAttributeAsString("continent");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.