Skip to content

Commit d2f262c

Browse files
author
Alan Cordeiro
committed
Support deep nested structures for mapMultiRowFields
1 parent 886c135 commit d2f262c

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,29 @@ export const mapMultiRowFields = normalizeNamespace((
7171
const store = this.$store;
7272
const rows = store.getters[getterType](path);
7373

74-
return rows
75-
.map((fieldsObject, index) => Object.keys(fieldsObject).reduce((prev, fieldKey) => {
76-
const fieldPath = `${path}[${index}].${fieldKey}`;
74+
const defineProperties = (fieldsObject, index, path) => {
75+
return Object.keys(fieldsObject).reduce((prev, fieldKey) => {
76+
77+
let fieldPath = index !== false ? `${path}[${index}].${fieldKey}` : `${path}.${fieldKey}`;
7778

7879
return Object.defineProperty(prev, fieldKey, {
7980
get() {
81+
if (typeof fieldsObject[fieldKey] === 'object' && fieldsObject[fieldKey] !== null) {
82+
return defineProperties(fieldsObject[fieldKey], false, fieldPath)
83+
}
8084
return store.getters[getterType](fieldPath);
8185
},
8286
set(value) {
8387
store.commit(mutationType, { path: fieldPath, value });
8488
},
8589
});
86-
}, {}));
90+
}, {})
91+
};
92+
93+
return rows
94+
.map((fieldsObject, index) => {
95+
return defineProperties(fieldsObject, index, path)
96+
});
8797
},
8898
};
8999

0 commit comments

Comments
 (0)