我有一个方法可以调用 addListener 来处理直到您单击按钮才存在的数据。但是,当我尝试在状态中设置该数据时,出现以下错误:
类型错误:this.setState 不是函数
我试过像这样绑定我的 dataHandler:
this.dataHandler = this.dataHandler.bind(this)
但它仍然返回此错误。我在这里忘记了什么?
constructor(props){
super(props)
this.state = {
selActive: 4,
loaded: false,
mapInfo: ''
}
this.onScriptLoad = this.onScriptLoad.bind(this)
this.dataHandler = this.dataHandler.bind(this)
}
dataHandler = (getJson) => {
fetch(getJson)
.then(response => response.json())
.then(featureCollection =>
dataLayer = map.data.addGeoJson(featureCollection)
);
map.data.addListener('mouseover', function(event) {
map.data.revertStyle();
map.data.overrideStyle(event.feature, {fillColor: 'blue'});
// THIS IS WHERE I ADD MY SETSTATE.
// HOWEVER, THIS RETURNS AN ERROR ON HOVER
this.setState({mapInfo: event.feature.countryNL})
});
}