我有一個在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