我正在对 SQL 数据库进行可视化表示,并使用 Francois Zaninotto 的CodeFlower(由 D3.js 提供支持)来完成。
我的问题是,如何访问被点击节点的父节点的名称变量?我意识到这个问题看起来类似于How to get data of parent node in d3.js但他们的答案对于我的目的似乎不清楚。我对 D3 也比较陌生,所以这可能就是原因。
我的json代码格式:
{"name":"CRS_LOG_LEVEL","children":[{"name":"CRS_LOG","children":[{"name":"LOG_DESC","size":7,"type":"column"},{"name":"LOG_ID","size":7,"type":"column"},{"name":"LOG_TMSTMP","size":7,"type":"column"},{"name":"LOG_LEVEL_NBR","size":7,"type":"column"},{"name":"LOG_EVENT_CD","size":7,"type":"column"}],"size":100,"type":"table"}],"size":100,"type":"root"}
我的鼠标点击事件监听器:
CodeFlower.prototype.click = function(d) {
// Toggle children on click.
if (d.children) { //This makes the node that has children collapse and grow in size.
d._children = d.children;
d.children = null;
} else {
var schemaName;
var tableName;
var columnName;
if(d.type==="column") //only check the parent information if type===column
{
columnName = d.name;
//tableName = Parent's name
//schemaName = Parent's Parent's name
}
d.children = d._children;
d._children = null;
}
this.update();
};
^ 上面的代码是我在这个问题顶部引用的 GitHub 项目中对 Francois 的 CodeFlower.js 的略微修改版本。