2
필자는 requirejs를 사용하는 성숙한 자바 스크립트 애플리케이션을 가지고 있으므로 전역 변수에 의존 할 수 없습니다. d3js 내 노드 네트워크 개념의 증명에서 실행하고 있지만 Tick 이벤트 수신기가 전달자 개체에 속성을 사용할 수 있도록 그것에 개체 참조를 전달해야합니다에서 Tick 이벤트 수신기에 문제가 있습니다.d3js Force Tick 이벤트에 인수를 전달하는 방법은 무엇입니까?
내가 현재 가지고 :
MyClass.prototype.SetupD3Force = function()
{
this.Force = d3.layout.force()
.size([200, 200])
.nodes([])
.charge(-120)
.on("tick", this.Tick);
// snip some code here
}
MyClass.prototype.Tick = function()
{
// Need to get hold of the sender's object properties
}
내가 할 수 있어야합니다 :
MyClass.prototype.SetupD3Force = function()
{
var width = 200;
var height = 200;
this.Force = d3.layout.force()
.size([width, height])
.nodes([])
.charge(-120)
.linkDistance(function(d) {
return d.value;
})
.on("tick", this.Tick, this); // Add a reference to the sender
// snip some code here
}
MyClass.prototype.Tick = function(sender)
{
// Now I can get hold of my properties
sender.MyProperties...
}
내가 실종 무엇인가? 어떻게 Tick 이벤트에 인수를 전달합니까?
도움 주셔서 감사합니다.
.on("tick", this.Tick.bind(this))
그리고 그들을 사용 : 틱 함수 내부의 "이"상황이 보낸 사람이 있지 않으면
감사합니다. 그게 효과가 있었어. 이제 내가 시도한 다른 포럼에서 답을 연결하십시오. :) –