// 目的将在线作图网站https://www.processon.com/的思维导图导出为Xmind文件
// 第一步 将其网站的返回参数简单处理后放到下边的a变量里
// 第二步 将得到的JSON文件 导入 https://c.runoob.com/more/kitymind/index.html 转化为 .km文件
// 第三部 将.km文件 通过 https://naotu.baidu.com/home 转化为 .xmind文件
const a = {
"leftChildren": [
{
"parent": "root",
"lineStyle": {
"randomLineColor": "rgb(255,204,204)"
},
"children": [
{
"parent": "45e3fc3c6c24",
"children": [],
"id": "47b321b4589c",
"title": "子主题"
},
{
"parent": "45e3fc3c6c24",
"children": [],
"id": "9bade95a458c",
"title": "子主题"
}
],
"id": "45e3fc3c6c24",
"title": "分支主题"
},
{
"parent": "root",
"lineStyle": {
"randomLineColor": "rgb(51, 156, 168)"
},
"children": [],
"id": "891aff16ce83",
"title": "分支主题"
},
{
"parent": "root",
"lineStyle": {
"randomLineColor": "#80BC42"
},
"children": [
{
"parent": "bb10e3347b4c",
"children": [],
"id": "734d71cfc4a4",
"title": "子主题"
},
{
"parent": "bb10e3347b4c",
"children": [],
"id": "2881e7709f64",
"title": "子主题"
}
],
"id": "bb10e3347b4c",
"title": "分支主题"
}
],
"note": "",
"children": [
{
"parent": "root",
"lineStyle": {
"randomLineColor": "#e85d4e"
},
"children": [
{
"parent": "e520c01f9a71",
"children": [],
"id": "ee503ee08072",
"title": "子主题"
},
{
"parent": "e520c01f9a71",
"children": [],
"id": "ec6a353f066d",
"title": "子主题"
}
],
"style": {
"color": "#null"
},
"id": "e520c01f9a71",
"title": "分支主题"
},
{
"parent": "root",
"lineStyle": {
"randomLineColor": "rgb(232, 124, 37)"
},
"children": [],
"id": "33ecba8c77f1",
"title": "分支主题"
},
{
"parent": "root",
"lineStyle": {
"randomLineColor": "#FDB813"
},
"children": [
{
"parent": "7899be7fe6eb",
"children": [],
"id": "458fc80f4609",
"title": "子主题"
},
{
"parent": "7899be7fe6eb",
"children": [],
"id": "83b70b98288d",
"title": "子主题"
}
],
"id": "7899be7fe6eb",
"title": "分支主题"
}
],
"background": "#ffffff",
"root": true,
"style": {
"background-color": "#ffffff"
},
"theme": "colorLines",
"id": "root",
"title": "中心主题",
"lines": {},
"structure": "mind_free"
}
// const b = {
// "data": {
// "id": "cvgu4fdbbu00",
// "text": "中心主题"
// },
// "children": [
// {
// "data": {
// "id": "cvgu4h256lc0",
// "text": "分支主题1"
// },
// "children": [
// {
// "data": {
// "id": "cvgu4n7y5ag0",
// "text": "分支主题"
// },
// "children": []
// }
// ]
// }]
// }
const b = {}
function convertObject(source) {
let target = {}
// 遍历所有字段
target.data = {
id: source.id,
text: source.title
}
if(Array.isArray(source.children) && source.children.length > 0){
target.children = source.children.map(item => convertObject(item))
}else{
target.children = []
}
return target;
}
console.log(JSON.stringify(convertObject(a)))
console