更新

addChild(data, parent)

在指定的父节点下添加子树。

参数

名称类型是否必选描述
dataobjecttrue子树的数据
parentNodestringtrue

用法

  1. const data = {
  2. id: 'sub1',
  3. children: [
  4. {
  5. id: 'subTree1',
  6. children: [...]
  7. },
  8. {
  9. id: 'subTree2',
  10. children: [...]
  11. }
  12. ]
  13. };
  14. treeGraph.addChild(data, 'root')

updateChild(data, parent)

更新数据,差量更新子树。

参数

名称类型是否必选描述
dataobjecttrue子树的数据
parentNodestringfalse

⚠️注意:当parent参数为空时,则全量更新。

用法

  1. const data = {
  2. id: 'sub1',
  3. children: [
  4. {
  5. id: 'subTree1',
  6. children: [...]
  7. },
  8. {
  9. id: 'subTree2',
  10. children: [...]
  11. }
  12. ]
  13. };
  14. treeGraph.updateChild(data, 'root')

removeChild(id)

删除指定的子树。

参数

名称类型是否必选描述
idstringtrue要删除的子树的ID

用法

  1. treeGraph.removeChild('sub');