问题
i have a restful api that accepts dotted(path) strings as parameter keys.
for example, i can call this:
/widgets?material.type=iron
so i have a redux-form field like:
<Field name="material.type" component={TextField} label="material type" />
but redux-form interprets the dot in material.type
and when passed to my handler ends up as {material: {type: 'iron'}}
.
i understand why this is the default behavior, but i was wondering if there is an easy way to thwart it with a property or something such that i can get {'material.type': 'iron'}
instead?
回答1:
This is not possible. Redux Form will always nest field values under objects when their name contain a dot - internally _.toPath is used, and it doesn't have a way to escape characters.
What you could do instead is to rename the value when assigning initialValues
:
initialValues: {
...formData,
materialType: formData['material.type']
}
...and when submitting the form:
onSubmit (values) {
return submitSomehow({
...values,
'material.type': values.materialType
})
}
来源:https://stackoverflow.com/questions/47536618/is-there-any-way-to-have-redux-form-ignore-dots-in-a-field-name