gpt4 book ai didi

javascript - 未捕获的类型错误 : Cannot read property 'state' of undefined

转载 作者:行者123 更新时间:2023-11-30 16:08:36 25 4
gpt4 key购买 nike

我有以下功能:

extractCountries: function() {
var newCountries = [];
_.forEach(this.props.countries, function(country) {

var monthTemp = Utils.thisMonthTemp(parseFloat(country["name"]["temperature"]));

if(parseFloat(country["name"]["safety"]) > this.state.minSafety &&
parseFloat(country["name"]["nature"]) > this.state.minNature &&
this.state.weather.min <= monthTemp &&
monthTemp <= this.state.weather.max) {

newCountries.push(country);
}
}).bind(this);
return newCountries;
}

在线 parseFloat(country["name"]["safety"]) > this.state.minSafety && 我得到:

未捕获的类型错误:无法读取未定义的属性“状态”

但我正在绑定(bind)外部 React 对象:

}).bind(this);

那么为什么会出现这个错误呢?

最佳答案

试试这个

extractCountries: function() {
var newCountries = [];
_.forEach(this.props.countries, function(country) {

var monthTemp = Utils.thisMonthTemp(parseFloat(country["name"]["temperature"]));

if(parseFloat(country["name"]["safety"]) > this.state.minSafety &&
parseFloat(country["name"]["nature"]) > this.state.minNature &&
this.state.weather.min <= monthTemp &&
monthTemp <= this.state.weather.max) {

newCountries.push(country);
}
}, this );
return newCountries;
}

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

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