我在Vaadin框架中有一个简单的TreeGrid。当我在树中展开具有50个或更多子级的节点时-javascript报告异常。而且只有前50个节点显示正确,而不是我看到的第一个节点是51个,而是我看到的是66个节点,而不是第16个7-7。
我尝试使用Vaadin 12.0.0、12.0.3、13.0.0.alpha2
我从Gradle使用插件'com.devsoap.vaadin-flow'版本'1.0.0.RC6'运行它
这是复制的简单示例。
import com.vaadin.flow.component.treegrid.TreeGrid;
import com.vaadin.flow.data.provider.hierarchy.AbstractHierarchicalDataProvider;
import com.vaadin.flow.data.provider.hierarchy.HierarchicalQuery;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
public class MyTreeGrid extends TreeGrid<MyTreeGrid.Node> {
private static final int CHILD_SIZE = 200;
public MyTreeGrid() {
this.addHierarchyColumn(Node::getName);
setDataProvider(new AbstractHierarchicalDataProvider<MyTreeGrid.Node, Void>() {
@Override
public boolean isInMemory() {
return false;
}
@Override
public int getChildCount(HierarchicalQuery<MyTreeGrid.Node, Void> query) {
Object node = query.getParent();
if (node == null)
return 1;
if (node instanceof RootNode)
return CHILD_SIZE;
return 0;
}
@Override
public Stream<MyTreeGrid.Node> fetchChildren(HierarchicalQuery<MyTreeGrid.Node, Void> query) {
Node node = query.getParent();
if (node == null) {
return Stream.of(new RootNode(0));
} else {
Stream<Node> nodeStream = IntStream.range(1, CHILD_SIZE + 1).mapToObj(Node::new);
Stream<Node> copy = IntStream.range(1, CHILD_SIZE + 1).mapToObj(Node::new);
int size = copy.collect(Collectors.toList()).size();
System.out.println(size);
return nodeStream;
}
}
@Override
public boolean hasChildren(MyTreeGrid.Node node) {
if (node == null)
return true;
return node instanceof RootNode;
}
});
}
public static class Node {
private final int num;
public Node(int num) {
this.num = num;
}
public String getName() {
return "Node " + num;
}
}
public static class RootNode extends Node {
public RootNode(int num) {
super(num);
}
public String getName() {
return "RootNode";
}
}
}