当前位置:网站首页>antd表单设置数组字段
antd表单设置数组字段
2022-07-17 12:35:00 【用户6256742】
在使用React+ant design进行开发时通常使用Form组件,但是很多时候我们某一个字段是二维数组。例如这样:
export const searchOptionContext = atom({
key: "article-list-option",
default: {
/** 发布人 管理员或者用户*/
auth: undefined,
/** 设置正序还是倒序*/
sort: ["create_time", "desc"],//这里
/** 时间线,查询某某之后create_time的文章*/
deadline: undefined,
/** 根据ID进行查询*/
article_id: undefined,
/** 发布者ID*/
author_id: undefined,
},
});但是表单每个item只对应了一个字段,怎么对多维数组中的每个元素进行设置呢?在仔细阅读文档后发现antd提供了一个list子组件来遍历多维数组。
在开发中只需要采取map对多维数组进行遍历即可:
通过索引值进行条件渲染,或者定义一个数组使用map的index参数进行渲染,不在需要条件判断。使用field中提供的key也可以,也是索引值。
<Form.List name="sort">
{fields =>
fields.map((field, index) => (
<Form.Item {...field} label={index == 0 ? "排序条件" : "规则"}>
<Select value={option.sort[index]} style={{ width: "120px" }}>
{index == 0 ? (
<>
<Option value="create_time">发布时间</Option>
<Option value="update_time">更新时间</Option>
<Option value="view_count">阅读数</Option>
</>
) : (
<>
<Option value="desc">降序</Option>
<Option value="asc">升序</Option>
</>
)}
</Select>
</Form.Item>
))
}
</Form.List>边栏推荐
- NJCTF 2017messager
- Blender digital twin production tutorial
- String type function transfer problem
- AutoJs学习-多功能宝箱-中
- R语言使用epiDisplay包的ordinal.or.display函数获取有序logistic回归模型的汇总统计信息(变量对应的优势比及其置信区间、以及假设检验的p值)、使用summary汇总统计
- Complete knapsack problem code template
- STM32F407 NVIC
- The new energy track has high risks, so please pay attention to safety
- 2022 Hunan secondary vocational group "Cyberspace Security" packet analysis infiltration Pacpng parsing (super detailed)
- HCIA 静态基础实验 7.8
猜你喜欢

基于微信小程序的外卖点餐系统
![高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷[.NET ORM]](/img/cb/76200539c59bb865e60e5ea1121feb.png)
高效理解 FreeSql WhereDynamicFilter,深入了解设计初衷[.NET ORM]

C# SerialPort配置和属性了解

LVI-SAM:激光-IMU-相机紧耦合建图

Domestic flagship mobile phones have a serious price foam, and second-hand phones are more cost-effective than new ones, or buy iPhones

What is pytest? Automated testing is a must

The use and Simulation of stack and queue in STL

为什么磁力变速齿轮会反转?

C语言之构造类型细讲

SAP Fiori 的附件处理(Attachment handling)
随机推荐
日期——贵州大学考研机试题目
R language uses the ordinal of epidisplay package or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence inter
HCIA OSPF
2022年陕西省中职组“网络空间安全”—数据包分析
YARN环境中应用程序JAR包冲突问题的分析及解决
Kirin Xin'an operating system derivative solution | host security reinforcement software, to achieve one click rapid reinforcement!
架构实战营|模块7
潇洒郎:VMware固定虚拟机IP地址
HCIA review and answer 2022.7.6
看一看这丑恶嘴脸 | MathWorks Account Unavailable - Technical Issue
How to realize the association between interfaces in JMeter?
C# SerialPort配置和属性了解
中职网络安全——(2022网络安全nc批量连接的脚本)免费的脚本哦~~~
创建虚拟机第一章(vmvare虚拟机)
微信小程序云开发 1 - 数据库
Three programming implementations to quickly determine whether the site is alive
Lvi-sam: laser IMU camera tight coupling mapping
R语言dplyr包select函数删除dataframe数据中包含指定字符串内容的数据列(drop columns in dataframe)
Analysis of the "Cyberspace Security" competition of Hunan secondary vocational group in 2022 (super detailed)
AutoJs学习-多功能宝箱-下