【问题标题】:Why can click not see update为什么可以点击看不到更新
【发布时间】: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


    【解决方案1】:
    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);
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-23
      • 2016-08-06
      • 2020-07-31
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多