我被困在一个非常简单的d.3问题......我有父子关系的节点。我正在尝试创建一个场景,我将单击除父节点之外的所有节点
我在想这样的事情呢?
.on(click, function(node){
if(!= node.parent){
window.location = d.url;
}
})
显然不起作用。这是什么语法?
这就是返回的json的样子。这将给出一个想法,我如何看到父母是什么,孩子是什么
functiongetNodes(){
varinNodes={
"name": "Test App",
"dept": "NYC",
"children": [
{
"name": "HPD Data Feeds",
"dept": "Third Party",
"category": "API",
"size": 15,
"url": "http://nycpdev.localhost:8082/api/hpd-data-feeds"
},
{
"name": "DOT Data Feeds",
"dept": "Third Party",
"category": "API",
"size": 15,
"url": "http://nycpdev.localhost:8082/api/dot-data-feeds"
},
{
"name": "HPD Data Feeds",
"dept": "Third Party",
"category": "App",
"size": 15,
"url": "http://nycpdev.localhost:8082/api/hpd-data-feeds"
}
],
"size": 20,
"url": "app/113"
};returninNodes;
}
答案 0 :(得分:0)
您可以直接从JSON获取节点是否有子节点:
.on(click, function(node){
if(!node.children){
window.location = d.url;
}
})