D3js selection.each () callback group argument
Simple html:
<div class="div1">
<div class="test"><span>1</span></div>
<div class="test"><span>2</span></div>
</div>
And js:
var el = d3.select(".div1").selectAll(".test");
el.each(function() {
console.log(arguments);
});
Conclusion:
[undefined, 0, 0]
[undefined, 1, 0]
What is the last argument (0)? According to the source code, this is a group, but I can not find anything about selector groups in the d3 documentation.
Thank.
+5
1 answer
This is for nested selectors: http://bost.ocks.org/mike/nest/
eg. for this HTML:
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
Let me choose td:
var el = d3.selectAll("tr").selectAll("td");
el [
Array[2]
,
Array[2]
]
and el.each:
el.each(function() {
console.log('args',arguments);
});
Conclusion:
args [undefined, 0, 0]
args [undefined, 1, 0]
args [undefined, 0, 1]
args [undefined, 1, 1]
+6