我有3个不同的对象/节点下方,我试图形成finalObj /节点这是3个节点的联盟(独特的树状列表)..
有没有用,我可以基于文本或ID联合3个对象(节点)树视图的方法?
First node:
[ { text: "TreeRoot", items: [
{ text: "Subgroup1" },
{ text: "Subgroup2" }
]}]
Second Node:
[ { text: "TreeRoot", items: [
{ text: "Subgroup3" }
]}]
Third node:
[{ text: "Subgroup3",
items: [ {
text: "subgroup5",
items: [ {
text: "subgroup6",
items: [ {
text: "subgroup7",
items: [ {
text: "subgroup8"
}]
}] }]
}]}]
Final expected node (after merging):
var finalObj= [ { text: "TreeRoot", items: [
{ text: "Subgroup1" },
{ text: "Subgroup2" },
{ text: "Subgroup3",
items: [ {
text: "subgroup5",
items: [ {
text: "subgroup6",
items: [ {
text: "subgroup7",
items: [ {
text: "subgroup8"
}]
}] }]
}]}]}]
编辑:
对于其他类型的节点下面的解决方案不工作..
对于EX:
var node1 = [
{ text : "TreeRoot",
id:0,
items: [
{ text: "Subgroup1",id:1 },
{ text: "Subgroup2", id:2}
]
}
];
var node2 = [
{
text : "TreeRoot",
id:0,
items: [
{ text: "Subgroup3" ,
id:3}
]
}
];
var node3 = [
{
text : "TreeRoot",
id:0,
items: [
{
text : "Subgroup2",
id:2,
items: [
{
text : "subgroup6",
id:6,
items: [
{
text : "subgroup7",
id:7,
items: [
{
text: "subgroup8",
id:8
}
]
}
]
}
]
}
]
}
];
对于上面的例子中,我应该首先看到的只是树的根部。 当扩大我应该看到的只是subgroup1,2,3 ......当subgroup2扩大我应该能够看到subgroup6,7,8。
我需要独特的父和子节点。如果我使用上面的结构,我得到2子节点named- Subgroup3