0

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

0

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;
    }
0

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);
    }
}; 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.