d3.select("xxx") .each(function (d) { //this表示当前element 而 d表示绑定的数据 something(this); });
注意each里的this,这个文档里说得明白http://rajapradhan.com/blogs/d3-js-v4-essentials/d3-selections/
The each() method
The each() method invokes the specified function for each of the selected element.
The ‘this’ inside the function refers to the current element of the selection being iterated.