D3.js-检查parenthnode值

发布于 2025-02-03 04:02:59 字数 816 浏览 2 评论 0原文

我想检查父节点是否等于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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2025-02-10 04:02:59

好的,我使用了以下功能来找到自定义“类型”参数的父节点的值:

if (d.type == 'program_outcome' && d.parent.type == '3program_outcome_group')
                    //do something

OK, I used the following which works to find the parent node's value for the custom 'type' parameter:

if (d.type == 'program_outcome' && d.parent.type == '3program_outcome_group')
                    //do something
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文