You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React 中如何将数组数据渲染为 Ant Design Select 下拉框选项?

实现方法

你需要遍历List数组,将每个元素封装为Ant Design的<Option>组件后传入Select即可,注意要给每个<Option>添加唯一的key属性避免React渲染警告。

你可以直接把原来的Select部分替换为如下代码:

<Select {...selectProps}>
  {List.map(item => (
    <Option key={item} value={item}>
      {item}
    </Option>
  ))}
</Select>

补充说明

如果运行时报组件未定义的错误,请补全antd相关组件的导入语句:

import { Select, Row, Col, Form, Button, Divider } from "antd";

内容的提问来源于stack exchange,提问作者pram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 16:06:09