D3.js-检查parenthnode值
我想检查父节点是否等于JSON数据中定义的特定类型。 例如,使用d3.js v4(是的,我知道...),
例如在JSON中:
{"name":"ABC", "type":"3program_outcome_group","children":[{"name":"XY","type":"program_outcome"},...
在此示例中,我想检查父节点的类型('type'为自定义参数)是否等于3program_outcome_group
。同时,我还需要检查子节点是否为program_outcome
。
我已经尝试过:
if (d.type == 'program_outcome' && d.parentNode.type == '3program_outcome_group' )
return d.name.substring(0, 6);
但是这是不起作用的...
而在没有检查parenthnode的情况下进行以下工作:
if (d.type == 'program_outcome')
return d.name.substring(0, 4);
我也尝试了:
if (d.type == 'program_outcome' && this.parentNode.type == '3program_outcome_group' )
return d.name.substring(0, 6);
I want to check if a parent node equals a certain type as defined in the JSON data. Using d3.js v4 (yes I know...)
For example in the JSON:
{"name":"ABC", "type":"3program_outcome_group","children":[{"name":"XY","type":"program_outcome"},...
In this example, I want to check if parent node's type ('type' being a custom parameter) is equal to 3program_outcome_group
. At the same time, I also need to check if the child node is of type program_outcome
.
I have tried:
if (d.type == 'program_outcome' && d.parentNode.type == '3program_outcome_group' )
return d.name.substring(0, 6);
But it's not working...
Whereas the following works without checking the parentNode:
if (d.type == 'program_outcome')
return d.name.substring(0, 4);
I have also tried:
if (d.type == 'program_outcome' && this.parentNode.type == '3program_outcome_group' )
return d.name.substring(0, 6);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我使用了以下功能来找到自定义“类型”参数的父节点的值:
OK, I used the following which works to find the parent node's value for the custom 'type' parameter: