我能够解决问题: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
在[{1}}上没有消失并且只停留在页面上时,该解决方案在scatterChart
tooltip
中导致了一个非常奇怪的错误。
我该如何解决?
答案 0 :(得分:0)
问题在于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