D3 Tree View是正确显示树所需的关键“孩子”

时间:2012-07-20 19:24:14

标签: json treeview d3.js

我有一个JSON,我从另一个来源获得在D3树视图中显示。 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"
                }
            ]
        }
    ]
}

1 个答案:

答案 0 :(得分:2)

您可以指定获取节点子节点的函数。请参阅the API documentation