antd 的 Form 和 Table 怎么一起使用?


import { useState } from "react";
import { Table, Form, Input } from "antd";

function TableFormValidate() {
    const [dataSource, setDataSource] = useState([
        { id: 1, name: 'a' },
        { id: 2, name: 'b' },
        { id: 3, name: 'c' },
    ])
    const columns = [
        { title: 'id', dataIndex: 'id' },
        {
            title: '名字', dataIndex: 'name',
            render: (text, record, index) => (
                <Form.Item name={[index, 'name']} rules={[{ require: true, message: '不能为空' }]}>
                    <Input />
                </Form.Item>
            )
        },
    ]
    return (
        <div>
            <Form defaultValue={dataSource}>
                <Table
                    columns={columns}
                    dataSource={dataSource}
                    pagination={false}
                    rowKey="id"
                />
            </Form >
        </div>
    )
}

export default TableFormValidate

期望:对每个表格里的输入框都能进行验证

阅读 3.2k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题