react-final-form - react-final-form 字段的动态名称
问题描述
我有 2 个表格。当我在第一个表单上选择一个选项时,第二个表单将添加到页面中,其中包含从后端检索的参数。现在如何将参数名称设置为 react-final-form 字段名称?
我找不到办法做到这一点。在哪里传递参数名称?
<Form
onSubmit={onSubmit}
validate={validate}
解决方案
React Final Form calls your onSubmit
function with the values from all the fields in your form. It's totally up to you to transmit the values to your server.
If you're asking how to build the second form, you just add the fields you need to add. So, say you got back from the server that you needed three fields: [ 'name', 'startTime', 'endTime' ]
. You'd just loop through that array and add the fields.
<Form onSubmit={onSubmit}>({handleSubmit}) => (
<form onSubmit={handleSubmit}>
{fieldsFromServer.map(fieldName => (
<div key={fieldName}>
<label>{fieldName}</label>
<Field name={fieldName} component="input"/>
</div>
))}
</form>
)}<Form>
Does that help? You don't have to "pass parameters to the form", you just add the Field
components that you need.
推荐阅读
- java - Mockito 的 argThat 在 Kotlin 中返回 null
- r - 当 A 列值匹配时,将 B 列 NA 替换为 B 列值
- angular - 使用设置 domLayout 打印网格
- scala - 将数据帧从 Spark 转换为 DL4j 使用的类型
- c# - C# File.ReadAllText() 不返回当前文件内容
- node.js - 使用下一条路线刷新路线
- javascript - JS:使用 find() 属性未定义的句柄
- php - 无法实例化邮件功能 - Codeigniter 和 PHPMailer
- ios - 获取 iOS 密码自动填充以使用“更改密码”页面
- node.js - 创建 Multer 存储引擎