我正在使用react js,在我的以下代码中我收到Uncaught TypeError: Cannot read property 'getHostNode' of null
错误。我已提到这个link。但在我的情况下它没有帮助。以下是我的代码:
for(var i=0;i<city.length;i++){
if(city[i]!= null){
if(i < 10){
cityListValues.push(<li key={"city-"+i} ><a onClick={this.updateCity} id={city[i].city_id} className={(this.props.city_name==city[i].name)? 'active':''}>{city[i].name}</a></li>);
} else{
break;
}
}
}
当我点击a tag
时,它第一次工作正常。但是,下次它总是抛出错误。我无法弄清问题是什么。调用该方法时,它会渲染大约5个组件并为所有组件设置状态。我在那里应用了上面提到的解决方案并在span
中插入了所有文本,但仍然不断收到错误。
城市数据:[{"city_id":202,"name":"abc","no_of_activities":1},{"city_id":175,"name":"xyz","no_of_activities":13},{"city_id":4612,"name":"pqr","no_of_activities":1},{"city_id":3,"name":"a1s2","no_of_activities":83},{"city_id":176,"name":"fgj","no_of_activities":1},{"city_id":172,"name":"ytu","no_of_activities":2},{"city_id":1092,"name":"mkju","no_of_activities":1}]
updateCity : function() {
var iso_code = '/';
this.props.changeCity(event.target.id);
if(this.props.country_id !== '99') {
for (var i=0; i<this.props.country_list.length; i++) {
if(this.props.country_id == this.props.country_list[i].country_id) {
iso_code = '/'+this.props.country_list[i].iso_code_2.toLowerCase()+'/';
}
}
}
browserHistory.push(iso_code);
},