使用javascript,客户端将json转换为树结构

时间:2014-11-11 11:34:49

标签: javascript json

我想将使用get请求收集的以下json代码转换为类似结构的树

"rules": [{
  "name": "Rule1",
  "isFirst": true,

  "conditions": [{
    "outcomeTrue": {
      "GoToRule": "Rule2"
    },
    "outcomeFalse": {
      "ChangeStatus": {
        "GoToRule": "26"
      }
    },
    "outcomeError": {
      "ChangeStatus": {
        "GoToRule": "27"
      }
    },
  }],
},{
  "name": "Rule2",
  "isFirst": false,
  "conditions": [{
    "name": "history check idNumber",
    "outcomeTrue": {
        "GoToRule": "27"
    },
    "outcomeFalse": {
      "GoToRule": "Rule3"
    },
    "outcomeError": {
      "GoToRule": "26"
    },

  }],
}]

这样的事情。只是一个像这样的普通图:

A tree like graph structure

1 个答案:

答案 0 :(得分:3)

查看D3.js' Tree

Live Example

编辑:另一个例子:D3.js tree diagram generated from 'flat' data(使用对象数组)

相关问题