caner 8 months ago
parent
commit
8507f34ab0
1 changed files with 11 additions and 0 deletions
  1. 11 0
      src/services/utils.service.ts

+ 11 - 0
src/services/utils.service.ts

@@ -41,6 +41,17 @@ export const groupBy = (array: any, key: string) => {
   }))
   }))
 }
 }
 
 
+/**
+ * 多维对象数组扁平化
+ * @param arr 原始数据
+ * @param key 递归key
+ * @returns
+ */
+export function recursion(arr: any[], key:string):any[] {
+  return ([]).concat(...arr.map((item) => (Array.isArray(item[key]) ? recursion(item[key], key) : item)))
+}
+
+
 /**
 /**
  * 对象转query
  * 对象转query
  * @param params
  * @param params