function getChildren(tasks, depth) {
let res = '';
if (tasks.children) {
tasks = tasks.children;
for (let i = 0; i < tasks.length; i++) {
console.log(tasks[i])
let child = getChildren(tasks[i], depth + 1);
//下面可以配置序号格式,默认 1. 2. 3. ....
res += (getNSpace(depth) + (i + 1) + "." + tasks[i].data.text + "\n")
if (child) {
res += child
}
}
}
return res;
}
function Calc() {
var tasks = document.getElementById("in").value;
let res = "";
tasks = tasks.substr(2);
try {
tasks = JSON.parse(tasks);
} catch (error) {
alert("输入格式异常,请重试");
}
if (tasks.length == 0) {
tasks = tasks[0];
} else {
tasks = {
children: tasks
};
}
res = getChildren(tasks, 0);
document.getElementById("out").value = res;
}
function getNSpace(n) {
let res = '';
while (n--)
//这里配置缩进长度,默认缩进两格
res += ' ';
return res;
}
百度脑图数据整理
请从百度脑图复制内容到此处:
一键复制
编辑
Web IDE
原始数据
按行查看
历史