我正在尝试迭代 D3.js 中的 X3DOM 节点,但出现错误。
这是代码:
var disktransform = scene.selectAll('.disktransform');
var shape = disktransform
.datum(slices)
.selectAll('.shape')
.data(partition.nodes)
.enter()
.append('shape')
.attr('class', 'shape')
.attr('data-name', function(d, i) { return d.name + ' ' + i; })
shape
.append('appearance')
.append('material')
.attr('diffuseColor', function (d, i) { return color(d.name); })
;
d3.selectAll('shape.shape').each(function (d) { console.log(d); d.node().addEventListener('click', function (event) { alert('key'); alert(d.attr('data-name')); }); });
这是错误。如您所见,它正在尝试使用HTMLUnknownElement.node()
. 如何让上述代码与 X3DOM 一起使用?
TypeError: d.node is not a function
at HTMLUnknownElement.<anonymous> (cross_chart.js:136)
at d3.js:962
at d3_selection_each (d3.js:968)
at Array.d3_selectionPrototype.each (d3.js:961)
at CrossChart.addPath (cross_chart.js:136)
at HTMLDivElement.<anonymous> (cross_chart.js:263)
at d3.js:962
at d3_selection_each (d3.js:968)
at Array.d3_selectionPrototype.each (d3.js:961)
at Array.CrossChart.draw (cross_chart.js:196)
(anonymous function) @ angular.js:10126
$get @ angular.js:7398
$get.Scope.$digest @ angular.js:12669
$get.Scope.$apply @ angular.js:12915
done @ angular.js:8450
completeRequest @ angular.js:8664
xhr.onreadystatechange @ angular.js:8603