I am working with angularjs and I have this response from my service and Its coming as tree and I am representing that data to the angular tree. this object have 4 main children, name and id. but these children and their children also have children, name and id. What I want is no matter which child I click, I always want to access the value of main root parent name thats "node1" "node2" "node3" as name so i know what is my main parent and whats parent under im clicking.
$scope.loadOrganizationTree = function () {
userManagementFactory.getOrganizationTree()
.success(function(data, status) {
if (JSON.stringify(data.statusType).indexOf("success") > -1) {
$scope.dataForTheTree = data.statusMsg;
}
} else {
$scope.setResponseMsgs(data, status);
}
}).error(function(data, status) {
$scope.userErrorMsg = data.statusMsg;
$scope.showErrorMSg = true ;
});
<div treecontrol class="tree-light accordion-org-tree"
style="height: 609px !important;" tree-model="dataForTheTree"
order-by="name" reverse-order="false" options="treeOptions"
on-selection="showSelected(node, selected, $parentNode, $index, $first, $middle, $last, $odd, $even)"
selected-node="node1" filter-expression="userProfileOrgSearch">
{{node.name}}
</div>
[
{
"id": 1,
"name": "node1",
"children": [
{
"id": 11,
"name": "node1.1",
"children": [
{
"id": 111,
"name": "node1.1.1",
"children": []
}
]
},
{
"id": 12,
"name": "node1.2",
"children": []
}
]
},
{
"id": 2,
"name": "node2",
"children": [
{
"id": 21,
"name": "node2.1",
"nodes": []
},
{
"id": 22,
"name": "node2.2",
"nodes": []
}
]
},
{
"id": 3,
"name": "node3",
"children": [
{
"id": 31,
"name": "node3.1",
"children": []
}
]
}
]
So far I have tried accessing with $parentnode but its not working out for me. Please let me know the solution. Thanks in advance.