我有一个数组列表,我正在使用 map 函数渲染它。每个对象都有一个单选按钮。现在,当我单击数据的单选按钮时,它显示“TypeError:无法读取未定义的属性'值'”。我不明白,我做错了什么。请在下面检查我的代码。
导入 React,{ Component } from 'react' import { withStyles, Typography, Grid, Radio } from '@material-ui/core';
class EventSupervisor extends Component {
constructor(props){
super(props);
this.state = {
lists: [
{id: 1, proImg: require("../../../../../assets/images/man-avatar.jpg"), imgAlt: 'Profile Image', name: 'Sam', role: 'Teacher'},
{id: 2, proImg: require("../../../../../assets/images/man-avatar.jpg"), imgAlt: 'Profile Image', name: 'Sam', role: 'Teacher'},
{id: 3, proImg: require("../../../../../assets/images/man-avatar.jpg"), imgAlt: 'Profile Image', name: 'Sam', role: 'Teacher'}
],
selectedValue: 1
}
}
handleChange=(e)=>{
this.setState({
selectedValue: e.target.value
})
}
render() {
const { classes } = this.props
return (
<div className= {classes.supervisorWrapper}>
<Grid container>
<Grid item xs='6'>
<Typography className={classes.selectContent}>Select Supervisor</Typography>
{/* <SupervisorList lists={this.state.lists} selectedValue={this.state.selectedValue} onChange={this.handleChange}/> */}
{
this.state.lists.map((list)=> {
return (
<div className={classes.superWrapper} key={list.id}>
<img src={list.proImg} alt={list.imgAlt} />
<Typography className={classes.supervisorName}>{list.name}<span className={classes.supervisorRole}>{list.role}</span></Typography>
<Radio
checked = {this.state.selectedValue === list.id}
onChange = {()=>this.handleChange(list.id)}
value = {this.state.selectedValue}
classes={{
root: classes.radioRoot,
checked: classes.rootChecked
}}
/>
</div>
)
})
}
</Grid>
<Grid item xs='6'>
</Grid>
</Grid>
</div>
)
}
}
export default withStyles(styles)(EventSupervisor)