I am trying to create an object in a getter for a lwc. For some reason when I declare the object, it is proxy object and does not retain any of the properties that I assign to it.
I am really struggling with this one. I declare the result object let result = new Object();
but when I log it it is a proxy object and is always empty, even after being assigned values in the for loop. I have tried the code in console and it works, assume it is something to do with the lwc system. let result = {};
doesn’t work either.
I am trying to transform a soql query to a nested object and then array of objects for my table, I’m not sure if it is the best approach to do it in a getter? Any advice on the approach would also be appreciated. Thanks!
import { LightningElement, wire, track, api } from 'lwc';
import getData from '@salesforce/apex/PermissionSetEditorController.getData';
export default class PermissionSetTable extends LightningElement {
@wire(getData) theData;
get tabledata() {
const uniqueFields = new Set();
console.log("uf inital", uniqueFields);
const uniquePermissionSetNames = new Set();
let result = new Object();
console.log(result);
if (this.theData && this.theData.data) {
// Derive uniqueFields
this.theData.data.forEach(item => {
uniqueFields.add(item.Field)
});
console.log('uf', uniqueFields);
// Derive uniquePermissionSetNames
this.theData.data.forEach(item => {
uniquePermissionSetNames.add(item.PermissionSetName)
});
console.log('uniquePermSetNames', uniquePermissionSetNames);
// set up nested object structure
console.log('ufsize', uniqueFields.size);
console.log("result before loop", result);
if (uniqueFields.size > 0) {
uniqueFields.forEach(field => {
// console.log('field', field);
result[field] = {};
//result[field] = {};
//console.log("in loop", result);
// uniquePermissionSetNames.forEach(permissionSetName => {
// result[field][permissionSetName] = '';
//});
});
console.log('result', result.size);
}
}
return Array.from(uniqueFields);
}
get responseReceived () {
if (this.theData) {
return true
}
false
}
}