如何将TreeModel应用于元素?

问题描述

我正在使用库TreeModel。除了没有显示如何在html中实际显示树之外,它还有很多文档。有人有线索吗?

我这样做是因为我正在构建二进制搜索树时练习我的数据结构,并且我想直观地看到代码的写法。 TreeModel似乎是最好的选择。

谢谢

解决方法

HTML文档本身是节点(元素)的树。 因此,如果需要显示树,则应使用HTML元素创建同一棵树。

例如

var myTree = {
  title: 'Root',children: [
    {
      title: 'child-1',},{
      title: 'child-2',}
  ]
};

等效于以下内容:

<div class="node">
  <p>Root</p>
  <div class="nodes">
    <div class="node">
      <p>child-1</p>
    </div>
    <div class="node">
      <p>child-2</p>
    </div>
  </div>
</div>
,

我找到了一个可行的解决方案。我所需要的只是为我的二叉树绘制图表的东西。这很好。我发布的应用程序并不是我想要的,但这很好用。

https://fperucic.github.io/treant-js/

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...