function getRelationship(data) {
var retData = new Array();
for (var i in data.node) {
var dataItem = {
name: data.node[i].name,
children: []
};
for (var j in data.link) {
if (data.link[j].source == i) {
var nodeName = data.node[data.link[j].target].name;
dataItem.children.push({
name: nodeName
});
}
}
retData.push(dataItem);
}
return retData;
}
var ret = getRelationship(data);
写个递归,循环遍历!
Code:
Result: