如何获取d3.js中父节点的数据 [英] How to get data of parent node in d3.js

查看:1522
本文介绍了如何获取d3.js中父节点的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



现在我在做

$

b
$ b

  d3.select(this).node()。parentNode .__ data__;有没有更好的方法?




< >解决方案

d3.select(this).node()相同在传递给D3选择的函数的上下文中。你可以像这样修改 d3.select(this.parentNode).datum(),并返回正确的值,而不必使用丑陋的双下划线属性。 p>

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.__data__;

Is there a better way?

解决方案

d3.select(this).node() is the same as just this in the context of a function passed to a D3 selection. You could rework it like this d3.select(this.parentNode).datum() and get the correct value back without having to use the ugly double-underscore property.

这篇关于如何获取d3.js中父节点的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆