I have 3 different object / node as below, and I am trying to form the finalObj / node which is the union (unique tree list) of the 3 nodes..
Is there a method in tree view with which I can union 3 objects (nodes) based on text or id ?
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"
}]
}] }]
}]}]}]
EDIT:
The below solution doesnt work for other type of nodes..
For 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
}
]
}
]
}
]
}
]
}
];
For above example I should see just tree root initially. When expanded I should see just subgroup1,2,3... and when subgroup2 is expanded I should be able to see subgroup6,7,8.
I need unique parent and child nodes.. If I use the above structure, I get 2 child node named- Subgroup3