reactjs - TypeError:无法读取未定义的属性“地图”反应this.props.rsl ['数据']
问题描述
我遇到了 map 函数的问题,它在控制台日志中显示数据,
console.log("iiiiiiiiii",this.props.rsl['data'])
但是当我使用 map 函数时{this.props.rsl['data'].map(row=>{})
,它会抛出一个错误说
它抛出错误说 TypeError: Cannot read property 'map' of undefined
render(){
const {classes}=this.props;
console.log("iiiiiiiiii",this.props.rsl['data'])
return(
<Paper className={classes.root}>
<div className={classes.tableWrapper}>
<Table>
<EnhancedTableHead rows={this.props.rowsHdr} />
{console.log("this.props.rowsHdr",this.props.rowsHdr)}
<TableBody>
{this.props.rsl['data'].map(row=>{
return(
<TableRow key={row.bankId}
hover
onClick={e=>console.log("e",e)}
>
<TableCell>{row.bankName}</TableCell>
<TableCell>{row.bankCode}</TableCell>
<TableCell>{row.city}</TableCell>
<TableCell>{row.country}</TableCell>
<TableCell>{row.status}</TableCell>
<TableCell>
<Button variant="contained" className={classes.button} onClick={()=>this.handleViewProfile(row.bankCode)}>
View
</Button>
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
</div>
</Paper>
)
}
iiiiiiiiii
(4) [{…}, {…}, {…}, {…}]
0: {status: "ACTIVE", zipcode: "500018", country: "India"}
1: {status: "ACTIVE", zipcode: "500019", country: "India"}
2: {status: "ACTIVE", zipcode: "500026", country: "India" }
3: {status: "ACTIVE", zipcode: "500028", country: "India"}
length: 4
__proto__: Array(0)
数据没有呈现,因为它没有映射,任何人都可以指导我知道出了什么问题。
解决方案
初始页面加载时,rsl
未定义,您可以通过以下方式解决问题
{this.props.rsl && this.props.rsl['data'].map(row => { ........... })
推荐阅读
- ios - Get time pressed in UILongPressGestureRecognizer
- javascript - 待办事项计数器的问题
- php - 将自定义样式格式添加到 TinyMCE(高级自定义字段)
- python - Python: Iterate through dictionary's keys' values with uneven number of values for each key
- python - Python对数据集中的相似记录(字符串)进行分组
- android - Android base layout with buttons to use in multiple activities
- javascript - 将请求正文作为 application/json 而不是纯文本/文本
- jira - 完成所有其他子任务后,查找带有“QA”等摘要的子任务
- linux - 如何在 linux ubuntu 中安装 python3 线程模块
- visual-studio - 如何在最新版本的 Visual Studio 中从文件开头搜索