用n个标签创建表单为代表值的字段
我想创建一个 tag 代表由API给出的字符串数组的列表。
import { Tag } from 'antd'
const TagList = () => {
const items = ['Tag1', 'Tag2', 'Tag3'];
return (
<>
{
items.map((item) => (
<Tag>{item}</Tag>
)
}
</>
)
}
我如何将其包装在a form.list.list 中,以便最终我可以将数据阵列发送回API端点?用例如重新排序的项目,例如['tag3','tag1','tag2']
我的第一种方法就像
<Form.List name={props.tagListName} initialValue={items}>
{(fields, { add, remove, move }) => {
return (
<div>
{fields.map((field) => (
<>
<Form.Item {...field}>
<CustomTagComponent
name={id}
closable={items.length > 1}
isDrag={activeId === id}
handleClose={onClose}
/>
</Form.Item>
</>
))}
</div>
)
}}
</Form.List>
我尝试将项目作为初始值添加到列表中,但这没有奏效。
如何创建items.length
标签,并结合包含这些值的表单?
I want to create a tag list which represents a string array given by an api.
import { Tag } from 'antd'
const TagList = () => {
const items = ['Tag1', 'Tag2', 'Tag3'];
return (
<>
{
items.map((item) => (
<Tag>{item}</Tag>
)
}
</>
)
}
How can I wrap this in a Form.List so that in the end I can send the data array back to an api endpoint? With let's say reordered items e.G. ['Tag3', 'Tag1', 'Tag2']
My first approach was like
<Form.List name={props.tagListName} initialValue={items}>
{(fields, { add, remove, move }) => {
return (
<div>
{fields.map((field) => (
<>
<Form.Item {...field}>
<CustomTagComponent
name={id}
closable={items.length > 1}
isDrag={activeId === id}
handleClose={onClose}
/>
</Form.Item>
</>
))}
</div>
)
}}
</Form.List>
I tried to add items as initialValue to the List, but that didn't work out.
How can I create items.length
tags, combined with a Form containing these values?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我想我找到了一个解决方案:
创建 codesandbox < /a>为此。
评论,意见或更好的解决方案赞赏:)
Ok, I think I found a solution:
Created a Codesandbox for it.
Comments, opinions or better solutions appreciated :)