当前位置:网站首页>Antd form setting array fields
Antd form setting array fields
2022-07-19 11:24:00 【User 6256742】
In the use of React+ant design When developing, we usually use Form Components , But many times, one of our fields is a two-dimensional array . Such as this :
export const searchOptionContext = atom({
key: "article-list-option",
default: {
/** Issued by Administrator or user */
auth: undefined,
/** Set positive or reverse order */
sort: ["create_time", "desc"],// here
/** Timeline , After querying so and so create_time The article */
deadline: undefined,
/** according to ID The query */
article_id: undefined,
/** Publisher ID*/
author_id: undefined,
},
});But every form item There is only one field , How to set each element in a multidimensional array ? After reading the document carefully, I found antd Provides a list Sub components to traverse the multidimensional array .
In development, we only need to take map You can traverse the multidimensional array :
Conditional rendering by index value , Or define an array to use map Of index Parameters to render , No longer need conditional judgment . Use field Provided in key It's fine too , Is also an index value .
<Form.List name="sort">
{fields =>
fields.map((field, index) => (
<Form.Item {...field} label={index == 0 ? " Sorting conditions " : " The rules "}>
<Select value={option.sort[index]} style={{ width: "120px" }}>
{index == 0 ? (
<>
<Option value="create_time"> Release time </Option>
<Option value="update_time"> Update time </Option>
<Option value="view_count"> Read the number </Option>
</>
) : (
<>
<Option value="desc"> Descending </Option>
<Option value="asc"> Ascending </Option>
</>
)}
</Select>
</Form.Item>
))
}
</Form.List>边栏推荐
- The type of MySQL index (single column index, combined index, BTREE index, clustered index, etc.)
- Develop the first Flink app
- Discussion on Euler angle solution of rocket large maneuvering motion
- PowerCLI 脚本性能优化
- Powercli script performance optimization
- SSM uses POI to export data to excel
- MySQL autoincrement ID, UUID and snowflake ID
- JVM钩子hooks函数
- Google Earth engine - Hansen global forest change v1.8 (2000-2020) forest coverage and forest loss data set
- Robot development -- robot data summary
猜你喜欢

Conversion of unity3d model center point (source code)

Deep Learning for Generic Object Detection: A Survey-论文阅读笔记

性能优化之@Contended减少伪共享

How does unity3d use the asset store to download some useful resource packages

剑指 Offer II 041. 滑动窗口的平均值

如何在 RHEL 9 中更改和重置忘记的root密码

Hot discussion: my husband is 34 years old this year and wants to read a doctoral degree. What should I do in the future to do scientific research?

LeetCode 558. Intersection of quadtree

Download of common getshell tools

Unity3d read mpu9250 example source code
随机推荐
常见分布式锁介绍
Unity3d 模型中心点的转换(源代码)
Qt--优秀开源项目
A fastandrobust convolutionalneuralnetwork-based defect detection model inproductqualitycontrol-阅读笔记
UE4 understanding of animation blueprint
Play with the one-stop scheme of cann target detection and recognition
JVM钩子hooks函数
Set the interface language of CMD command prompt window to English
What should I do if I can't see any tiles on SAP Fiori launchpad?
Daily question brushing record (26)
《MySQL DBA封神打怪之路》专栏学习大纲
CodeForces - 587E(线性基+线段树+差分)
学习笔记3--规划控制中的机器学习基本思想
Model comparison of material inventory management between sap ECC and s4hana material
LeetCode 745. Prefix and suffix search
How much money can you make by inventing flash memory? This is a Japanese dog blood story
Déléguer un chargeur tel qu'un parent
Mysql优化系列之limit查询
Tencent cloud server uses image to deploy WordPress personal website!
数据库锁的介绍与InnoDB共享,排他锁