樹形資料遍歷

2022-08-22 16:21:08 字數 1761 閱讀 6351

tree

樹形結構如下:

graph lr

key:1-->key:1-1;

key:1-->key:1-2;

key:1-1-->key:1-1-1;

key:1-1-->key:1-1-2;

key:1-1-2-->key:1-1-2-1;

key:1-1-2-->key:1-1-2-2;

key:1-2-->key:1-2-1;

key:1-2-->key:1-2-2;

key:1-2-->key:1-2-3;

key:1-2-3-->key:1-2-3-1;

key:1-2-3-->key:1-2-3-2;

輸入陣列[ '1-2-1' , '1-2-3-2' ]要求輸出如下樹形結構:

graph lr

key:1-->key:1-2;

key:1-2-->key:1-2-1;

key:1-2-->key:1-2-3;

key:1-2-3-->key:1-2-3-2;

實現**如下:

mapchangearray(arr, disabled?) 

if (this.defaultcheckedkeys.some(x => x === o.key))

if (o.children && object.prototype.tostring.call(o.children) === '[object array]' && o.children.length > 0)

});} // 設定樹

settree(item)

findpathbfs(source, goal)

return result;

})(curdata);

}// 如果有 children 則 push 進 res 中待搜尋

if (curdata.children) ));}}

// 沒有搜尋到結果,預設返回空陣列

return ;

} setprop(arr, path)

if (item.children && object.prototype.tostring.call(item.children) === '[object array]' && item.children.length > 0)

});} flitertree(arr)

if (arr[i].children && object.prototype.tostring.call(arr[i].children) === '[object array]' && arr[i].children.length > 0)

}}

呼叫方式:

this.mapchangearray(this.treeall);

this.flitertree(this.treeall);

this.treelist = json.parse(json.stringify(this.treeall));

輸入樹形資料:

this.treeall = [,,

],"id": 211,

"label": "dashboard_card"}],

"id": 209,

"label": "dashboards"}],

"id": 208,

"label": "dashboard_manage"},,

]}

]

樹形資料轉換

測試資料 create table project id int,name nvarchar 20 parent id int insert project select 1,所有專案 null union all select 2,專案1 1 union all select 3,專案2 1 cr...

樹形資料轉換

測試資料 create table project id int,name nvarchar 20 parent id int insert project select 1,所有專案 null union all select 2,專案1 1 union all select 3,專案2 1 cr...

樹形資料轉換

測試資料 create table project id int,name nvarchar 20 parent id int insert project select 1,所有專案 null union all select 2,專案1 1 union all select 3,專案2 1 cr...