javascript/d3-将参数传递给函数
我正在使用一个名为d3的javascript库来对对象执行一些动画。在每个动画结束时,我想调用一个函数,该函数从调用动画的对象传递数据,但它不起作用。我如何做到这一点?这是我的密码:javascript/d3-将参数传递给函数,javascript,d3.js,Javascript,D3.js,我正在使用一个名为d3的javascript库来对对象执行一些动画。在每个动画结束时,我想调用一个函数,该函数从调用动画的对象传递数据,但它不起作用。我如何做到这一点?这是我的密码: function selectArcs() { d3.selectAll("g.arc > path") .each(arcTween) } function arcTween(d,i){ console.log(i); //registers as 0, then 1
function selectArcs() {
d3.selectAll("g.arc > path")
.each(arcTween)
}
function arcTween(d,i){
console.log(i); //registers as 0, then 1
d3.select(this)
.transition().duration(1000)
.attrTween("d", tweenArc({ init : d.value }))
.each("end",function(i){ console.log(i); }); //registers as 0, then 0 - should be 0, then 1
}
在function(i){console.log(i);}
中,您正在调用参数i
,但实际上它通常被称为d
尝试用
函数(dor){console.log(i);}
替换它(这应该从函数arcTween(d,i)
中获取i
变量)是!非常感谢您的回复。