1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
export function recurTree(tree) { let res = []; let nodeArr = []; const findPath = (res, tree, nodePath) => { if (tree.children) { tree.children.forEach((item, index) => { findPath(res, tree.children[index], [...nodePath, item.unitId]) }) } else { res.push(nodePath); } } findPath(res, tree, nodeArr); }
[ [ "3_1", "3_5", "4_1" ], [ "3_1", "3_5", "4_12", "4_13" ], [ "3_1", "3_5", "4_12", "4_14" ], [ "3_1", "3_5", "4_2" ], [ "1_111", "2_1082" ], [ "1_111", "3_11", "4_15" ] ]
|