我解决了这个问题:Uncaught TypeError: Cannot read property 'showBarChart' of undefined in React
var that = this;
chart.tooltip.contentGenerator(function (d) {
var html = "<div>";
d.series.forEach(function(elem){
Object.keys(data_obj).forEach(function(key_1) {
var outer_obj = data_obj[key_1];
if (outer_obj["key"] === elem.key) {
that.showBarChart(elem.key);
var expr = outer_obj["values"][0]["expr"];
html += "<p>" + elem.key + "</p>";
html += "<p>x = " + d.value + ", y = " + elem.value + "</p>";
}
});
})
html += "</div>";
return html;
});然而,这个解决方案导致了nvd3 scatterChart中的一个非常奇怪的错误,当tooltip没有消失在mouse out上而只停留在页面上时。

我怎么才能修好它?
发布于 2017-12-27 22:38:51
问题是,在componentDidUpdate中,我给createScatterChart打了电话。我把它评论掉了,它开始运作得很好。它的发生显然是因为React工作流,我在问题:Trace why a React component is re-rendering中发现了这个工作流。
componentDidMount() {
this.createScatterChart()
}
componentDidUpdate() {
//this.createScatterChart()
}Calling this.setState() within the component. This will trigger the following component lifecycle methods shouldComponentUpdate > componentWillUpdate > render > componentDidUpdate
https://stackoverflow.com/questions/47999322
复制相似问题