gpt4 book ai didi

javascript - ×类型错误: Cannot read property 'borders' of undefined

转载 作者:行者123 更新时间:2023-12-02 21:35:21 28 4
gpt4 key购买 nike

不确定为什么会收到此错误:

render() {
14 | let { params } = this.props.match
15 | let country = this.state.countries.find(country => country.cca· === params.id)
> 16 | let countryBorders = country.borders.map(border => this.state.countries.find(country => country.cca3 === border && country))
| ^ 17 |

18 |返回 ( 19 | 19

最佳答案

国家的值(value)是什么?您需要确保您没有尝试访问尚不存在的值的属性。

尝试这样的事情:

countryBorders = country && country.borders.map(border => this.state.countries.find(country => country.cca3 === border && country)) || []

关于javascript - ×类型错误: Cannot read property 'borders' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60513531/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com