+ Start a Discussion
Anil Bolisetty 2Anil Bolisetty 2 

Any examples to build nested json data for lightning:tree using helper class and not have the logic at apex

Hello,

Need to use lightning:tree ,i want to have the logic to build the nested json in controller.js rather than controller which uses apex

Thanks in advance for the help
Raj VakatiRaj Vakati
You can able to find it in the example .. Is this what you are looking ??
 
({
    init: function (cmp) {
        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" :[]
                }]
            }]
        }, {
            "label": "Eastern Sales Director",
            "name": "5",
            "expanded": false,
            "items": [{
                "label": "Easter Sales Manager",
                "name": "6",
                "expanded": true,
                "items" :[{
                    "label": "NY Sales Rep",
                    "name": "7",
                    "expanded": true,
                    "items" :[]
                }, {
                    "label": "MA Sales Rep",
                    "name": "8",
                    "expanded": true,
                    "items" :[]
                }]
            }]
        }, {
            "label": "International Sales Director",
            "name": "9",
            "expanded": true,
            "items": [{
                "label": "Asia Sales Manager",
                "name": "10",
                "expanded": true,
                "items" :[{
                    "label": "Sales Rep1",
                    "name": "11",
                    "expanded": true,
                    "items" :[]
                }, {
                    "label": "Sales Rep2",
                    "name": "12",
                    "expanded": true,
                    "items" :[]
                }]
            },{
                "label": "Europe Sales Manager",
                "name": "13",
                "expanded": false,
                "items" :[{
                    "label": "Sales Rep1",
                    "name": "14",
                    "expanded": true,
                    "items" :[]
                }, {
                    "label": "Sales Rep2",
                    "name": "15",
                    "expanded": true,
                    "items" :[]
                }]
            }]
        }];
        cmp.set('v.items', items);
    }
})



https://developer.salesforce.com/docs/component-library/bundle/lightning:tree/example
 
Anil Bolisetty 2Anil Bolisetty 2
You have hard coded it could you help me the same iwth jaavscript programatically