1

I am trying to work with lwc tree-grid and move the results returned from my query display there related data.

However it looks like the return is now non-extensible and as such you can no longer simply do the following to get the data into the '_children' property

@wire(fetchTimesheets) timeSheetRate({ error, data }) { if (data) { let objs = []; for ( var i = 0; i < data.length; i++ ) { console.log(JSON.parse(JSON.stringify(data[i]))); let obj = data[i]; if(obj['Timesheet_Rates__r']) { obj._children = obj[ 'Timesheet_Rates__r' ]; delete obj.Timesheet_Rates__r; } console.log(JSON.parse(JSON.stringify(obj))); objs.push(obj); } this.gridData = objs; } else if (error) { console.log('An error has occurred:'); console.log(error); } }; 

Any ideas, The only thing i can think of at this point would be return a class so Apex rather then the objects

3 Answers 3

1

Using a json parse i was able to pass the data into a new variable and from there i could use a map on my new list do change the values on a new list and put it back into the tracked proporty

if (data) { let objs = JSON.parse(JSON.stringify(data)); objs.map(e =>{ if(e[ 'Timesheet_Rates__r' ]){ e._children = e[ 'Timesheet_Rates__r' ]; } }) this.gridData = objs; } 
1

I would prefer clone the array first and then work on that array.

@wire(fetchTimesheets) timeSheetRate({ error, data }) { if (data) { let objs = [...data]; objs.forEach(function(obj){ if(obj['Timesheet_Rates__r']) { obj._children = obj[ 'Timesheet_Rates__r' ]; delete obj.Timesheet_Rates__r; } }); this.gridData = objs; } else if (error) { console.log('An error has occurred:'); console.log(error); } }; 
0

According to this reference, JSON is not extensible because it does not need to be. JSON is not a document markup language, so it is not necessary to define new tags or attributes to represent data in it.

So you need to make a copy of the parsed object onto a conventional JS object which supports property extension.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.