gpt4 book ai didi

java - GWT:如何使用 AsyncDataModel 填充 CellTree 的初始列表?

转载 作者:行者123 更新时间:2023-12-02 00:36:34 25 4
gpt4 key购买 nike

我正在使用 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 不是正确的类型吗? - 戴夫

最佳答案

// summarizing pseudocode
public <T> NodeInfo<?> getNodeInfo(final T value) {
if(value == null) { // root, return static list of top level nodes
return new DefaultNodeInfo<String<(
new ListDataProvider<String>(Arrays.<String>asList("node1", "node2" ... ));
, new TextCell());
}
else {
AsyncDataProvider<String> dataProvider = new AsyncDataProvider<String>() {
@Override
protected void onRangeChanged(HasData<String> display) {
// Execute dynamic logic here - and fetch data from server or wherever
// call updateRowData() in when data is available
updateRowData(display.getVisibleRange(), /* List<String> results */);
}
}

return new DefaultNodeInfo<String>(dataProvider, new TextCell());
}
}

关于java - GWT:如何使用 AsyncDataModel 填充 CellTree 的初始列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7654089/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com