I have a requirement, to display specific data on custom component.
- Data is grouped by parameter into an object (up to 13)
- Object contains array of objects
- Object into array have 3 another parameters
unique_key_name1: [{
outcome: 'string',
quote: 'string',
source: 'string'
},{
outcome: 'string',
quote: 'string',
source: 'string'
}],
unique_key_name2: [{
outcome: 'string',
quote: 'string',
source: 'string'
},{
outcome: 'string',
quote: 'string',
source: 'string'
}]
I need to create accordion section into component with unique_key_name into accordion label and all values from array object inside.
I have no idea, how to iterate through object (and don't even know, is it possible). Any ideas for solution or tips with displaying whole objects ?
Maybe I need to rebuild data received from controller, and this format I described is wrong ?
I appreciate any help !
Best Answer
You can't iterate over objects, you iterate over arrays. That means you need to convert your object-style data into array-style data. For example:
Which transforms your data into:
From here, you can iterate over your output:
If the fields were also dynamic, you'd have to also convert them into an array suitable for displaying the values. Something like the following would probably be sufficient: