gpt4 book ai didi

reactjs - Redux Form、Radio Button Fields、如何支持变量值?

转载 作者:行者123 更新时间:2023-12-03 13:40:07 25 4
gpt4 key购买 nike

在我的 React Redux 表单中,我有以下内容:

        <fieldset className="form-group">
<legend>Radio buttons</legend>
{this.props.job_titles.map(jobTitle => (
<div className="form-check" key={jobTitle.id}>
<label className="form-check-label">
<Field
name="job_title_id"
component="input"
type="radio"
value={jobTitle.id}
/>
{' '}
{jobTitle.title}
</label>
</div>
))}
</fieldset>

这会正确呈现单选按钮,但是当您单击以选择单选按钮时,单选按钮永远不会设置为选中状态。您无法选择选项 - 表单已损坏。

奇怪的是,如果我将 value={jobTitle.id} 更新为 value="anything",则可以选择单选按钮。

我在 redux 表单文档中没有看到任何有关动态生成的单选按钮的内容。我做错了什么?

谢谢

最佳答案

将值转换为字符串:

<Field
name="job_title_id"
component="input"
type="radio"
value={jobTitle.id.toString()}
/>

关于reactjs - Redux Form、Radio Button Fields、如何支持变量值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44895103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com