问题描述
我正在使用React Final Form,由于某种原因,当我尝试将初始值传递给它的initialValues
道具时,如果我使用的键的格式为'key6.value'
,则它不起作用-具有该名称的Field
保持为空.但是,如果格式不包含,它将起作用.在中间,例如'key6value'
.
I'm working with React Final Form, and for some reason, when I try to pass initial values to its initialValues
prop, it doesn't work if the keys I use are in the format 'key6.value'
- the Field
with that name stays empty. It does, however, work if the format doesn't have the . in the middle, e.g. 'key6value'
.
为什么initialValues不能用于这些嵌套字段(名称带有.的字段)?我该怎么做才能使其通过initialValues
?
Why doesn't initialValues work for these nested fields (fields with names that have the .)? And what can I do to make it pass the initialValues
?
我已经对此进行了彻底的测试,以确保我确定了问题,并且填充字段与不填充字段之间的唯一区别是.在其name
属性中.
I've tested this thoroughly to make sure I identified the issue, and the only difference between having the Fields populate and not has been the . in their name
attribute.
推荐答案
您需要使用实际的嵌套结构进行初始化.不是这样的:
You'll need to initialize with the actual nested structure. Not like this:
{
'key5.value': 'init value' // ❌
...
}
赞:
{
key5: {
value: 'init value' // ✅
}
...
}
有帮助吗?
这篇关于在React Final Form中,为嵌套字段提供initialValues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!