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);
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