我有一个关于动态地将Sencha元素渲染到DOM的问题。我在页面上有一个按钮,用于从DB加载用户,并且必须呈现Basic Grid。我有以下代码:
Button users = new Button("Users", new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
userServiceAsync.getUsers(new AsyncCallback<List<User>>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("ololo!");
}
@Override
public void onSuccess(List<User> result) {
center.add(new com.google.gwt.user.client.ui.Button("OloloBtn")); // this renders
center.add(new UserTable(result)); // and this not
center.layout(true);
}
});
}
});
UserTable代码:
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;
import com.myproject.client.model.User;
import java.util.ArrayList;
import java.util.List;
public class UserTable extends LayoutContainer {
private List<User> users;
public UserTable(List<User> users) {
this.users = users;
}
@Override
protected void onRender(Element parent, int index) {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
configs.add(new ColumnConfig("login", "Login", 100));
configs.add(new ColumnConfig("email", "Email", 100));
configs.add(new ColumnConfig("firstName", "First Name", 100));
configs.add(new ColumnConfig("lastName", "Last Name", 100));
ListStore<User> listStore = new ListStore<User>();
listStore.add(users);
ColumnModel cm = new ColumnModel(configs);
Grid<User> grid = new Grid<User>(listStore, cm);
ContentPanel cp = new ContentPanel();
cp.setBodyBorder(false);
cp.setHeading("Employee List");
cp.setLayout(new FitLayout());
cp.setSize(700, 300);
cp.add(grid);
add(cp);
}
}
因此,用户从DB加载。问题在于将表格转换为页面。在按钮监听器的onSuccess方法中,我试图渲染GWT Button,这很好用。但是用户表不会附加到DOM。怎么了?
感谢您的回答。
答案 0 :(得分:0)
当您输入覆盖时,需要致电super.onRender(parent, index)
。