Browse Source

数组 flatObject

zzx 3 years ago
parent
commit
a6563aec39
1 changed files with 11 additions and 3 deletions
  1. 11 3
      src/lib/systemLib.ts

+ 11 - 3
src/lib/systemLib.ts

@@ -142,10 +142,18 @@ export function flatRow(array) {
 function flatObject(parentObj, parentProp, obj) {
     _.forOwn(obj, (value, key) => {
         const fullKey = parentProp ? parentProp + '_' + key : key
-        if (typeof value === 'object') {
-            flatObject(parentObj, fullKey, value)
+        if(_.isArray(value)) {
+            parentObj[fullKey] =  _.map(value, (row) => {
+                const newRow = {}
+                flatObject(newRow, '', row)
+                return newRow
+            })
         } else {
-            parentObj[fullKey] = value
+            if (typeof value === 'object') {
+                flatObject(parentObj, fullKey, value)
+            } else {
+                parentObj[fullKey] = value
+            }
         }
     })
 }