javascript - React 将数组映射到下拉问题
问题描述
对话框.js
const Dialog = ({label, onClose, open}) => {
handleSubmit=()=>{};
return (
<Form onSubmit={handleSubmit}>
{() => (
<Dialog
onClose={onClose}
open={open}
title={() => label}
content={() => <RatingTable />}}
action={() => {}}
/>
)}
</Form>
)
}
RatingTable.js
const RatingTable = ()=> {
return(
<table>
<thead>
<tr>
<header1>
<header2>
</tr>
<thead>
<tbody>
{PeopleList.map(People=>(
<PeopleRow {...people} id={people.id} name={people.name}>
))}
</tbody>
</table>
)}
PeopleList.js
const List = [
{id:1, name:"jack", sex:"male", age:23},
{id:2, name:"marry", sex:"female", age:18},
{id:3, name:"paul", sex:"male", age:12},
{id:4, name:"katty", sex:"female", age:20}
]
const PeopleArray = List.reduce(
(acc, {age}) =>{
acc.push(age);
return acc;
},[]);
PeopleRow.js
const PeopleRow = name => {
return (
<tr>
<td>
<TextField value={name}>
</td>
<td>
<DropDownField source={PeopleList}>
</td>
</tr>
)
}
所以理想情况下,我想要PeopleArray
哪个是我的DropDownFiled
组件中显示的年龄数组,但是有些年龄值没有显示在下拉列表中,它只显示文本选择 4 次。我想让下拉列表可以从 中的 4 个年龄中选择peopleArray
。
解决方案
在 RatingTable.js 文件中,您将术语拼错people
为People
.
const RatingTable = ()=> {
return(
<table>
<thead>
<tr>
<header1>
<header2>
</tr>
<thead>
<tbody>
{PeopleList.map((people) => ( // Change this, replace `People` with `people`
<PeopleRow {...people} id={people.id} name={people.name}>
))}
</tbody>
</table>
)}
推荐阅读
- java - C++ 像 Java 中的 Map?
- django - 当 ModelForm.save 完成运行时,Django 保存覆盖用户失败
- ios - 我使用 CFNotificationCenter 将消息从主机应用程序发送到 widgetExtension,但发现它没有用
- javascript - 如何处理开玩笑的抛出异常
- mysql - Percona Server5.6 Master-maser replication 一些网络错误
- slick.js - 在反应光滑的图像中显示箭头和点
- recurrent-neural-network - RuntimeError:CUDA 错误:触发了设备端断言
- python - 如何在 python 笔记本单元格的同一输出中显示 .png 图像和 imput() 表单?
- php - 使用声明不适用于 Yii2 供应商
- python - python中定义的函数内部未定义值