When I assign hardcoded Javascript JSON in LWC then the Tree Grid gets rendered.
const items = [{label:"Premier League",name:"Premier League",type:"League",treeIcon:'custom:custom48',_children:[],expanded:false,},
{label:"Bundesliga",name:"Bundesliga",type:"League",treeIcon:'custom:custom48',_children:[],expanded:false,},
{label:"La Liga",name:"La Liga",type:"League",treeIcon:'custom:custom48',_children:[],expanded:false,},
{label:"Serie League",name:"Serie League",type:"League",treeIcon:'custom:custom48',_children:[],expanded:false,},
{label:"Major League Soccer",name:"Major League Soccer",type:"League",treeIcon:'custom:custom48',_children:[],expanded:false,}]
When I store this same JSON in database field, retrieve it & assign it dynamically On Load then Tree Grid doesn't get rendered.
JS -
@track treeList;
@wire(getRecord, { recordId: 'a0h6F00000RcvAqQAJ', fields: FIELDS })
wiredRecord({ data }) {
if (data) {
window.console.log('On Load Data ::: ' + JSON.stringify(data.fields.Hierarchy_Structure__c.value));
let dat = data.fields.Hierarchy_Structure__c.value;
let tree = dat.replace(/\\/g, '');
window.console.log('On Load Tree List ::: ' + tree);
this.treeList = tree; // **I pass treeList as data to Lightning Tree Grid**
}
}
HTML -
<lightning-tree-grid
key-field="name"
columns={columns}
data={treeList}
</lightning-tree-grid>
No error is shown when component gets loaded. I just am not able to understand what is the problem here.