gpt4 book ai didi

jquery - 显示节点树

转载 作者:行者123 更新时间:2023-12-01 01:49:57 25 4
gpt4 key购买 nike

Possible Duplicate:
Javascript library for node-based objects and object relationships?

是否有任何 Jquery 插件或任何解决方案,可以在给定此数据表的情况下显示节点关系表(一个节点有一个父节点和多个子节点)?

最佳答案

您希望它们以什么方式显示?

以下是一些插件的列表:http://www.webdesignbooth.com/15-great-jquery-plugins-for-better-table-manipulation/

我可以向您展示这个,您可以对其进行修改以满足您的需求。它所做的就是通过对象图进行递归。请注意,可以通过编辑 function newDiv 代码来更改其样式。

(function () {
var jsonData = dataSentFromServer();
var detailsElement = document.getElementById("Details");
function newDiv(txt) {
var createDiv = document.createElement("div");
if (txt != undefined)
createDiv.innerHTML = txt;
return createDiv;
}

var depth = 1;
(function ComposeGraph(obj, el) {
var ElementArray = [];
var ChildArray = [];
$.each(obj, function (name, value) {
if (!$.isArray(value)) {

var appender = newDiv(name + " __:__ " + value);
appender.setAttribute("style", "margin-left:" + 10 * depth + "px;");
if ($.isPlainObject(value)) {
appender.innerHTML = "<b>" + appender.innerHTML + "</b>";
depth++;
ComposeGraph(value, appender);
depth--;
ElementArray.push(el);
ChildArray.push(appender);
} else {
el.appendChild(appender);
}
} else {
var appender = newDiv(name + " __:__ " + value);
appender.setAttribute("style", "margin-left:" + 10 * depth + "px;");
appender.innerHTML = "<b>" + appender.innerHTML + "</b>";
for (var i = 0, len = value.length; i < len; i++) {
depth++;
ComposeGraph(value[i], appender);
depth--;
}
ElementArray.push(el);
ChildArray.push(appender);
}
});
for (var i = 0, len = ElementArray.length; i < len; i++) {
ElementArray[i].appendChild(ChildArray[i]);
}
})(jsonData, detailsElement);
})();

关于jquery - 显示节点树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13130691/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com