我有一个从其他来源获取的 JSON,可以在 D3 TreeView 中显示。 JSON 是树形结构,但不使用关键字“children”来定义子节点。我对传入的 JSON 没有任何控制权,并且表示子节点的文本可能会发生变化。 D3 Tree View 是否完全依赖于关键字“children”,或者 D3 是否有办法使用其他字符串来表示子节点?
下面是我收到的 JSON 的简化版本。
{ "name": "some string", "score": "0.29", "weight": "0.8", "task1": [ { "name": "some string", "score": "0.19", "weight ": "0.2", "subtask1": [ { "score": "0.11", "weight ": "0.1", "name": "some string" } ] } ], "task2": [ { "name": "some string", "score": "0.19", "weight ": "0.2", "subtask1": [ { "score": "0.11", "weight ": "0.1", "name": "some string" } ] } ] }
最佳答案
您可以指定函数来获取节点的子节点。请参阅the API documentation .
关于json - D3 TreeView ,是正确显示树所需的关键 "children",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11585731/