我有一个在mousedown上调用的函数。然后我想调用另一个函数,但是“this”是mousedown对象。那么我该如何调用this.function?Angular 2&d3:当函数存在时如何调用此函数
start()
{
d3.select(#svgArea)
.append("rect")
.attr("id", "newRect")
.attr("x", 10)
.attr("fill", "#FFFFFF")
.attr("stroke", "#666666")
.attr("y", 10)
.attr("width", 250)
.attr("height", 100)
.on("mousedown",() => { d3.event.stopPropagation(); })
.on("click", function() { d3.event.stopPropagation(); })
.on("mousedown", this.selected)
.on("mouseup", this.unselected));
}
selected()
{
if(d3.event.button == 0)
{
var box = d3.select(this).node().getBBox();
var Obj = d3.select(this);
var Obj2 = d3.select(this).node().parentNode.parentNode;
d3.select("#freedraw")
.append("rect")
.attr("id", "bottomRight")
.attr("x", ((box.x + box.width)) + 3)
.attr("y", ((box.y + box.height)) + 3)
.attr("width", 6)
.attr("height", 6)
.attr("stroke", "#666666")
.attr("fill-opacity", 0)
.style("cursor","se-resize");
d3.select("#bottomRight")
.call(d3.drag()
.on("drag", this.dragging));//<--Here is the issue
}
}
}
dragging()
{
console.log("dragging");
}
“本”中的“选择”功能的上下文中是对象上的用户鼠标按下(在该实例中是一SVG RECT)。因此,在我标记为“< - 这里是问题”的区域中,它正在使用this.function,但所做的只是选择了rect.function。
如何从这里调用我的函数“拖动”?
如果你不喜欢这样,那么你不能指与“此”内选择的功能的鼠标按下对象。 – echonax
你可以通过它在正确的? – danday74
你是什么意思?像输入一样? – echonax