效果:
实现代码
//this.vals指的是要转换的数据
dataFormSubmit() {
let a = this.vals.split("\n");
var f = [];
for (let i = 0; i < a.length; i++) {
f.push(a[i].split("/"));
console.log(a[i].split("/"));
}
this.switchTree(f);//获取的树形数据
},
//将获取的一维数组转为树形结构数组
switchTree(arr) {
arr.forEach((k) => this.add(k));
console.log(result);
return result;
},