【发布时间】:2011-10-04 21:12:05
【问题描述】:
我正在使用 GWT 2.4。我想创建一个具有一组固定的顶级节点的树,但是在打开每个节点时,都会从服务器动态检索数据。我找到了 AsyncDataProvider 类来帮助我,但我无法弄清楚如何使用一组初始值预填充数据模型。我有这个代码(不工作)...
public class CellTreeExample implements EntryPoint {
/**
* The model that defines the nodes in the tree.
*/
private static class CustomTreeModel implements TreeViewModel {
/**
* Get the {@link NodeInfo} that provides the children of the specified
* value.
*/
public <T> NodeInfo<?> getNodeInfo(T value) {
/*
* Create some data in a data provider. Use the parent value as a prefix
* for the next level.
*/
AsyncDataProvider<String> dataProvider = new AsyncDataProvider<String>() {
@Override
protected void onRangeChanged(HasData<String> display) {
// Execute dynamic logic here.
}
};
// Set a default set of nodes.
TextCell textCell = new TextCell();
final CellList<String> cellList = new CellList<String>(textCell);
final List<String> rootNodes = getRootNodes();
cellList.setRowCount(rootNodes.size(), true);
dataProvider.addDataDisplay(cellList);
// Return a node info that pairs the data with a cell.
return new DefaultNodeInfo<String>(dataProvider, new TextCell());
}
public boolean isLeaf(Object value) {
// some logic
}
}
public void onModuleLoad() {
// Create a model for the tree.
TreeViewModel model = new CustomTreeModel();
/*
* Create the tree using the model. We specify the default value of the
* hidden root node as "Item 1".
*/
CellTree tree = new CellTree(model, "Item 1");
// Add the tree to the root layout panel.
RootLayoutPanel.get().add(tree);
}
当我启动我的应用程序并且我已经确认初始单元格列表包含 6 个项目时,什么都没有出现。任何想法为什么他们不显示?构造用于 CellTree 的 CellList 时,TextCell 是否不适合使用? - 戴夫
【问题讨论】: