Skip to content

Commit 79dc7a8

Browse files
authored
fix: form和content的key没有对应上,导致find取不到item对象 (#203)
1 parent 50269fb commit 79dc7a8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/util/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export function transformOutputValue(value, content) {
4343
const newVal = {}
4444
Object.keys(value).forEach(id => {
4545
const item = content.find(item => item.id === id)
46+
if (!item) return
4647
if (item.type !== 'group') {
4748
if (item.outputFormat) {
4849
const v = item.outputFormat(value[id])

test/utils.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,39 @@ describe('transformOutputValue', () => {
129129
]
130130
expect(transformOutputValue(v, content)).toEqual(v)
131131
})
132+
133+
test('form oldV和content的key没有对应上的情况', () => {
134+
const oldV = {
135+
a: 1,
136+
b: {
137+
c: 2,
138+
d: 3,
139+
},
140+
}
141+
const newV = {
142+
b: {
143+
c: 1,
144+
e: 4,
145+
},
146+
}
147+
const content = [
148+
{
149+
id: 'b',
150+
type: 'group',
151+
items: [
152+
{
153+
id: 'c',
154+
outputFormat: c => c - 1,
155+
},
156+
{
157+
id: 'd',
158+
outputFormat: d => ({e: d + 1}),
159+
},
160+
],
161+
},
162+
]
163+
expect(transformOutputValue(oldV, content)).toEqual(newV)
164+
})
132165
})
133166

134167
describe('transformInputValue', () => {

0 commit comments

Comments
 (0)