0
我有一個關於動態地將Sencha元素渲染到DOM的問題。我有頁面上的按鈕,從DB加載用戶,並且必須呈現Basic Grid。我有下面的代碼:渲染GXT元素
用戶表的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);
}
});
}
});
代碼:
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。哪裏不對?
感謝您的回答。