从javascript函数读取动态更新值

从javascript函数读取动态更新值,javascript,d3.js,Javascript,D3.js,} 该代码基本上在甘特图中删除了一个svg rect元素,该元素是可移动的。当我在图表中移动svg块时,rect的x和y坐标被更新。我想读取它们并将它们存储在一个变量中。欢迎就如何做提出建议。提前谢谢您已经在读取x坐标了。您不明白什么会阻止您同时读取y坐标?问题是我无法访问返回值x_start。当我试图在另一个函数中访问它时,它会说它未定义。有没有一种方法可以使其在全球范围内可用?问题似乎是您正在更新z_start,但返回此.x_start..我的直觉是两者都不同。。因此,与其执行return

}


该代码基本上在甘特图中删除了一个svg rect元素,该元素是可移动的。当我在图表中移动svg块时,rect的x和y坐标被更新。我想读取它们并将它们存储在一个变量中。欢迎就如何做提出建议。提前谢谢

您已经在读取x坐标了。您不明白什么会阻止您同时读取y坐标?问题是我无法访问返回值x_start。当我试图在另一个函数中访问它时,它会说它未定义。有没有一种方法可以使其在全球范围内可用?问题似乎是您正在更新z_start,但返回此.x_start..我的直觉是两者都不同。。因此,与其执行return this.x_start,不如执行return x_start
if(recipe_Num == 0)

{
    color = "rgb(0,191,255)";
}

else if(recipe_Num == 1){
    color = "rgb(255,255,0)";
}
else{
    color = "rgb(255,110,180)";
};
if(recipe[recipe_Num].step[step_Num].stage == 0){
    y_stage = 25;
}
else if(recipe[recipe_Num].step[step_Num].stage == 1){
    y_stage = 50;
}
else if(recipe[recipe_Num].step[step_Num].stage == 2){
    y_stage = 75;
}
else if(recipe[recipe_Num].step[step_Num].stage == 3){
    y_stage = 100;
}
else if(recipe[recipe_Num].step[step_Num].stage == 4){
    y_stage = 125;
}
else{
    y_stage = 150;
};

  if(x_recipe[recipe_Num]>=x_stage[recipe[recipe_Num].step[step_Num].stage]){
    x_start = x_recipe[recipe_Num];
}
else{
    x_start = x_stage[recipe[recipe_Num].step[step_Num].stage];
}
     function updatex()

   {
        x_recipe[recipe_Num] = x_start+pt;
        x_stage[recipe[recipe_Num].step[step_Num].stage] = x_start+pt;
    }

     function dragmove(d) 

    {
       d3.select(this)
      .attr("x", Math.round((d3.event.x-80)/25)*25+80);
    }



   function insert()
  {
    var bodySelection = d3.select(".chart");
    var circleSelection = bodySelection.append("rect")
                                  .attr("x", this.x_start)
                                  .attr("y", this.y_stage)
                                  .attr("width", this.pt)
                                  .attr("height", 25)
                                  .style("fill", this.color)
                                  .call(drag);

return this.x_start;
return this.pt;