【发布时间】:2011-11-17 16:35:16
【问题描述】:
我有部门列表,每个部门可能有一个父或没有,部门域对象是如下:
- departmentId
- parentDepartmentId (null if current department has no parent i,e should be under root directly, and have value if current department have parent).
.
.
.
查看用于创建基本树的 icefaces 教程代码:
// create root node with its children expanded
DefaultMutableTreeNode rootTreeNode = new DefaultMutableTreeNode();
IceUserObject rootObject = new IceUserObject(rootTreeNode);
rootObject.setText("Root Node");
rootObject.setExpanded(true);
rootTreeNode.setUserObject(rootObject);
// model is accessed by by the ice:tree component via a getter method, this object is what's needed in the view to display the tree
model = new DefaultTreeModel(rootTreeNode);
// add some child nodes
for (int i = 0; i <3; i++) {
DefaultMutableTreeNode branchNode = new DefaultMutableTreeNode();
IceUserObject branchObject = new IceUserObject(branchNode);
branchObject.setText("node-" + i);
branchNode.setUserObject(branchObject);
rootTreeNode.add(branchNode);
}
这都是关于构建基本节点和添加子节点的。
我的情况很复杂,根目录下的 child A 可能有子 节点 B、C、D 和 D 例如 子节点等等。
所以我正在考虑如何完成这样的事情的最佳实践,如果有人可以提供帮助,我需要一个示例代码或提示。
【问题讨论】:
-
在上面的代码中,如果这是一个方法,并且如果数据库中的数据有更多的子记录,那么您将在同一方法中递归调用该方法,这将构建您的树。跨度>
-
请给你代码,还不能给你。
标签: java jakarta-ee tree icefaces