Skip to content
Advertisement

How to restructure parent child details in JavaScript, retrieved from database?

I am trying to display parent( Survey ) & child ( Survey participants ) details retrieved from the database ( Salesforce ).

I am using LWC ( Lightning web component ) to display the details.

There is a limitation in lwc that you can’t access data from a related object using ‘__r’ ( This means related object ) directly in HTML component.

Here is my data:

JavaScript

I need to prepare it something like this :

JavaScript

I have tried using two-approach but none of them are working as expected :

Approach 1: I am trying to use collection.map

JavaScript

It’s not allowing to iterate through the nested structure.

Approach 2: nested data.foreach method.

Please let me know how I can fix the above issue.

Thank you in advance.

Advertisement

Answer

Here is a working stackblitz example

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement