How to get data of parent node in d3.js

后端 未结 3 1584
北恋
北恋 2020-12-14 14:52

I am doing nesting in D3 and in a nested element, I need to reach data object on its parent.

Right now I am doing

d3.select(this).node().parentNode._         


        
3条回答
  •  Happy的楠姐
    2020-12-14 15:34

    The other method I'm familiar with is to use .each() on the parent, and then deal with children within the closure:

    d3.selectAll('.parent').each(function(parentDatum) {
        d3.select(this).selectAll('.child').each(function(childDatum) {
            // do stuff with parentDatum and childDatum here
        });
    });
    

提交回复
热议问题