function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mohammed AzarudeenMohammed Azarudeen 

Display Account and its related Contacts in lightning:tree view

I just came to know about lightning:tree tag which is a cool tag to represent the role hierarchy.

Am trying to display Account and its related contacts in this lightning:tree structure. Through some examples from salesforce, I can able view tree structure with some hard coded value but it'll be helpful if I can load the dynamic Account and its related Contacts in this lightning:tree view.

Ex from salesforce:
Component
<aura:component>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="items" type="Object"/>
    <lightning:tree items="{! v.items }" header="Roles"/>
</aura:component>
Controller
({
    doInit: function (cmp, event, helper) {
    var items = [{
            "label": "Western Sales Director",
            "name": "1",
            "expanded": true,
            "items": [{
                "label": "Western Sales Manager",
                "name": "2",
                "expanded": true,
                "items" :[{
                    "label": "CA Sales Rep",
                    "name": "3",
                    "expanded": true,
                    "items" : []
                },{
                    "label": "OR Sales Rep",
                    "name": "4",
                    "expanded": true,
                    "items" : []
                }]
            }]
        }];
        cmp.set('v.items', items);
    }     
})

User-added image
 
Naveen KNNaveen KN
I think you need to frame the record set as a JSON object in the server side controller and pass it to the client side. In the client side map the JSON recordeset to the 'v.items'