[英]how can i keep track of "Ant Design- Dynamic Form Item" and store all values in a single object state?
So I'm using Ant Design Dynamic Form Item and you can create as many as input field you want.所以我正在使用 Ant Design 动态表单项,您可以创建任意数量的输入字段。
the question is how can I store all of the values (static field and new fields)
in a single array of objects
inside my state?问题是如何将所有值
(static field and new fields)
存储在我的状态内的单个array of objects
?
Please take a Look at my component请看一下我的组件
if you click add it will create another Autocomplete and a inputfield.如果您单击添加,它将创建另一个自动完成和一个输入字段。 and you enter data
然后你输入数据
for example I want an array of object like this例如我想要一个这样的对象数组
[{commisionFor: 'Invoicing' , perctange: 10},{newcondition: 'something' , percentage: 32},{} , {} , {] , and etc ]
I wanna achieve this.我想实现这个。 how can i do this ?
我怎样才能做到这一点 ? I will appreciate your help
我会感谢你的帮助
PS : I'm not typing my code here because it's to complex and I don't even know what i did. PS :我没有在这里输入我的代码,因为它很复杂,我什至不知道我做了什么。 Take look at this Ant Design Dynamic Form Item sandbox
看看这个 Ant Design Dynamic Form Item 沙箱
you can use onChange event to store all values separately.您可以使用 onChange 事件分别存储所有值。
const [values, setValues] = useState({})
const onChangeHandler = (name, value) =>{
let data = values;
data[name] = value;
setValues(data)
}
and in your multiple input field, create unique name for each input field.并在您的多个输入字段中,为每个输入字段创建唯一名称。
fields.map((name, index) => {
<Input placeholder={name} name={name} onChange={(e) => onChangeHandler(name, e.target.value)} />
})
use your own attribute for naming fields or just use the index value.使用您自己的属性来命名字段或仅使用索引值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.