【发布时间】:2023-01-08 15:18:08
【问题描述】:
我正在构建一个基于 d3js 的 javascript 主页。在将一些代码从功能代码重组为 OOP 时,点击方法无法找到更新方法。我收到 Uncaught ReferenceError: this.update is not defined。我认为它与范围有关,但我对 js 很陌生,所以他们很难弄明白,有什么想法吗?
class UpdateTree{
update(source){}
enter_new_nodes_at_the_parents_previous_position(node, source){
var nodeEnter = node.enter().append("g")
.attr("class", "node")
.attr("transform", function (d) { return "translate(" + source.y0 + "," + source.x0 + ")"; })
.on("click", this.click);
click(d) {
if (d.children) {
d._children = d.children;
d.children = null;
} else {
d.children = d._children;
d._children = null;
}
this.update(d);
}
}
【问题讨论】:
标签: javascript d3.js