【发布时间】:2012-01-12 21:29:20
【问题描述】:
我正在尝试使用 GXT 框架创建一个相当简单的 GWT 应用程序,并根据电子书“Ext GWT 2.0 Beginners Guide”进行此操作。它详细介绍了使用 GXTs MVC 模型构建应用程序的所有步骤,其中大部分都按预期工作,但是我不能 - 在它的生命周期内 - 将新行添加到我的网格中。
Grid 数据的初始加载(通过 itemStore、loader 和 RPCProxy 工作正常)。
但是,每次我触发触发添加新行的事件时,我想要添加的 ListStore 都是空的(不是 null!而是空的)——即使我的 Grid 在初始加载后显示数据!
以下是一些相关代码:
public class MessageGrid extends LayoutContainer {
private final Grid<ModelData> grid;
private final ListLoader<ListLoadResult<MarketingMessage>> loader;
private final ListStore<ModelData> itemStore;
public MessageGrid() {
setLayout(new FitLayout());
final MarketingServiceAsync marketingService = Registry.get(MarketingUIConstants.MARKETING_SERVICE);
RpcProxy<List<MarketingMessage>> proxy = new RpcProxy<List<MarketingMessage>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<List<MarketingMessage>> callback) {
marketingService.getMessages(callback);
}
};
final List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("col1", "Name", 100));
columns.add(new ColumnConfig("col2", "Phone", 100));
final ColumnModel columnModel = new ColumnModel(columns);
loader = new BaseListLoader<ListLoadResult<MarketingMessage>>(proxy);
itemStore = new ListStore<ModelData>(loader);
grid = new Grid<ModelData>(itemStore, columnModel);
grid.setBorders(true);
grid.setAutoExpandColumn("sentTime");
grid.setAutoHeight(false);
grid.setHeight("100%");
}
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
loader.load();
add(grid);
}
public void addMessage(MarketingMessage marketingMessage) {
itemStore.add(new MarketingMessage("test", "test")));
}
}
addMessage() 正在被所属组件(已添加此 LayoutContainer 的视图)调用。
如果我在 addMessage() 方法中设置断点,我的 itemStore 的大小为 0(同样适用于 grid.getStore())。
我已尝试对此代码进行各种不同的更改,但尚未看到添加了一行。
类似的说明:如果在 addMessage() 方法中,我尝试从代理重新加载 - 因为我也更新了服务器端数据 - 即。 loader.load(),它也没有任何可见的效果。
【问题讨论】: