我正在尝试使用 XTemplate 来显示网格的行信息:
List<User> users = new ArrayList<User>();
users.add(new User("John", "Smith"));
users.add(new User("Bob", "James"));
UserList list = new UserList(users);
XTemplate tpl = XTemplate.create(getTemplate());
tpl.applyTemplate(Util.getJsObject(list));
RowExpander expander = new RowExpander();
if (showExpand){
expander.setTemplate(tpl);
columns.add(expander);
}
下面是 getTemplate() 的代码:
public native String getTemplate() /*-{
return ['<p>Details: ',
'<tpl for=".">',
'<p>{#}</p>', // use current array index to autonumber
'</tpl></p>'
].join("");
}-*/;
但是我对 XTemplate 还是很陌生,而且我似乎无法让它工作。我只是用样本复制了一些来源。
基本上,我要做的只是将上述内容呈现List<User>
为:
Details:
1 First Name: John - Last Name: Smith
2 First Name: Bob - Last Name: James
这是User和UserList模型:
class User extends BaseModelData {
public User(String firstName, String lastName){
set("firstname", firstName);
set("lastname", lastName);
}
}
class UserList extends BaseModelData {
public UserList(List<User> list){
set("users", list);
}
public List getUsers(){
return get("users");
}
public void setUsers(List users) {
set("users", users);
}
}
这是 Grid 的声明方式:
Grid grid = new Grid<ModelData>(new ListStore<ModelData>(), new ColumnModel(columns));
这是 ListStore 的详细信息:
ListStore<ModelData> store = grid.getStore();
store.removeAll();
store.add(list); // Where list is List<Map<String, String>> data