我如何跟踪“蚂蚁设计 - 动态形式”项目。并将所有值存储在一个对象状态中?

发布于 2025-02-04 21:22:33 字数 821 浏览 1 评论 0原文

因此,我使用的是ant Design 您可以创建所需的输入字段。

问题是如何将所有值(静态字段和新字段)存储在我的状态中的单个数组中?

请查看我的组件

如果单击单击,请添加它将创建另一个autocompletete和aputfield。例如,您输入数据

,例如,我想要这样的对象,

[{commisionFor: 'Invoicing' , perctange: 10},{newcondition: 'something' , percentage: 32},{} , {} , {] , and etc ]

我想实现这一目标。我该怎么做?我将感谢您的帮助

PS :我不是在这里键入代码,因为这很复杂,我什至不知道自己做了什么。看看这个蚂蚁设计动态表单sandbox

ant动态表单codesandbox

So I'm using Ant Design Dynamic Form Item and you can create as many as input field you want.

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?

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. Take look at this Ant Design Dynamic Form Item sandbox

Ant Dynamic Form Item CodeSandBox

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2025-02-11 21:22:33

您可以使用Onchange事件单独存储所有值。

const [values, setValues] = useState({})

const onChangeHandler = (name, value) =>{
   let data = values;
    data[name] = value;

   setValues(data)
}

在您的多个输入字段中,为每个输入字段创建唯一名称。

 fields.map((name, index) => {
    <Input placeholder={name} name={name} onChange={(e) => onChangeHandler(name, e.target.value)} />
})

将自己的属性用于命名字段,或者仅使用索引值。

you can use onChange event to store all values separately.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文