0

嘿伙计们,我一直在努力寻找解决问题的方法。我想在我的 JavaFx 应用程序中实现 ControlsFX CheckTreeView。基本上我有一个字符串列表,其格式与网站上的导航栏相匹配。到目前为止,示例 Admin.Config.User 将是字符串之一。我已经解析了这些字符串并将它们转换为 LinkedHashMap,其中每个拥有孩子的父母都将存储每个孩子的列表和孩子的 CheckBoxTreeItem。

创建 CheckTreeView 对象时,您可以传递 Root CheckBoxTreeItem 或不带参数进行初始化。

CheckBoxTreeItem 文档

我很难想象如何构建一个从底部到根 CheckBoxTreeItem 的树。

// Contains the Nodes with children and corresponding CheckBoxTreeItems
LinkedHashMap<String, LinkedHashMap<String, CheckBoxTreeItem<String>>> navPaths = new LinkedHashMap<String, LinkedHashMap<String, CheckBoxTreeItem<String>>>();

// Was thinking about using this as a check to make sure duplicates are not added
LinkedHasMap<String, String> alreadyAdded = new LinkedHashMap<String, String>

// Check Tree View
CheckTreeView<String> checkTreeView = new CheckTreeView<>();

for(String pathNode : navPaths.keySet()){

    for(String childName : testPaths.get(pathNode).keySet()){

        // Completely lost once I get here
    }
}

// Set built root
//checkTreeView.setRoot();

我真的在这个概念上苦苦挣扎,以至于我还没有走得很远,如果看起来我没有付出任何努力,我深表歉意。在过去的 12 个小时里,我一直在思考这个概念,但我对此一无所知。如果有人可以为我提供一些帮助,那将非常感谢。

4

1 回答 1

0

我建议摆脱链接的哈希映射,直接解析为 CheckBoxTreeItem(它可能是您完成此任务所需的唯一数据结构)并(也许)使用递归算法而不是迭代算法。

这是一个树的插入算法,在您的解析例程中使用类似的东西将您解析的每个元素直接插入到由 CheckBoxTreeItems 定义的树中。请注意,您将无法完全使用该算法,您将开发一种适合您特定需求的算法。

我想我真的不应该回答这个问题,因为它很不清楚,但是信息太长了,无法发表评论……至少它可能会让你开始走另一条路。

于 2015-10-20T12:18:31.453 回答