0

I am trying to flatten the @wire decorator so i can get __r fields into my datatable, and I am failing miserably

let me show you what i have tried, none of which has worked

try 1: mapping

columns = [
    { label: 'Name', fieldName: 'Name' },
    { label: 'Household Name', fieldName: 'HouseholdName'}
];
@api recordId;
householdTags;
@wire(getData, {FundInterestPriorityId: '$recordId'})
wiredContacts({ error, data }) {
    if (this.data) {
                this.data = this.data.map(row=>{
                    return{...row, HouseholdName: row.ucinn_ascendv2__Account__r.Name}
                })
    
                this.householdTags = this.data;

try 2: object / array mapping

if (this.data) {
            let preparedAssets = [];
            this.data.forEach(asset => {
            let preparedAsset = {};
            preparedAsset.Name = asset.Name;
            preparedAsset.HouseholdName = asset.ucinn_ascendv2__Account__r.Name;
            preparedAssets.push(preparedAsset);
            window.console.log(preparedAssets)

            });
            this.data = preparedAssets;

            this.householdTags = this.data;

my html

<lightning-datatable
key-field="id"
data={householdTags}
columns={columns}>
</lightning-datatable>
0

1 Answer 1

0

You wrote:

if(this.data) {
  this.data = this.data...

Which is never set. You meant:

if(data) {
  this.data = data...

Keep in mind that this means you're trying to access the component's properties, while without this, it means you're accessing a locally defined or static variable (one outside the class or imported).

P.S. I wrote a function that automates the flattening process so you don't have to keep reinventing the wheel every time.

2
  • updated that piece but still does not fix the issue
    – Jay Rizzi
    Commented Oct 4, 2022 at 16:58
  • @JayRizzi Please edit your question to show the updated code, I'll take another look.
    – sfdcfox
    Commented Oct 4, 2022 at 17:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .