OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

object declared in lwc getter is proxy object

  • Thread starter Thread starter code-not-clicks
  • Start date Start date
C

code-not-clicks

Guest
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!

Code:
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
  }
}

<p>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.</p>
<p>I am really struggling with this one. I declare the result object <code>let result = new Object();</code>
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. <code>let result = {};</code>doesn't work either.</p>
<p>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!</p>
<pre class="lang-js prettyprint-override"><code>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
}
}
</code></pre>
 

Latest posts

S
Replies
0
Views
1
Safwan Aipuram
S
Top