You need to sign in to do that
Don't have an account?
ryanschierholz
Combine three custom objects into a nested array to display on a Lightning web component
The ultimate goal is to be able to iterate over an array in a Lightning web component to show internal reviews about our vendors. There would be at least three levels: Super Category, Category, Review (maybe even four: Super Category, Category, Vendor, Review), so that the root lists are not repeated in the display. For example:
Super Category 1
-Category A
--Review 00
--Review 01
-Category B
--Review 02
Super Category 2
-Category C
--Review 03
Super Category is Parent over Category, which is parent over Review. Review also has references to Super Category.
ultimately the array might look like this:
What is the best way to accomplish this? In the Controller or the .js of the component? And how?
Super Category 1
-Category A
--Review 00
--Review 01
-Category B
--Review 02
Super Category 2
-Category C
--Review 03
Super Category is Parent over Category, which is parent over Review. Review also has references to Super Category.
ultimately the array might look like this:
superCategories = [ { Name: 'Additions', Categories: [ { Name: 'Bathroom Additions', Reviews: [ { Vendor: 'Jay at Pritches Closets', Rating: 5, Comment: 'this is the comment', Phone: '8005551234' } ] }, { Name: 'Kitchen Additions', Reviews: [ { Vendor: 'Phil Dunphy', Rating: 4, Comment: 'this is the comment', Phone: '8005551234' } ] } ] } ];
What is the best way to accomplish this? In the Controller or the .js of the component? And how?
-- Assuming we need only super categories having atleast one Categorys.Reviews
2. If there are more than one review for a Vendor in a category, only show the Vendor/Review once, but show the number of 'duplicates'.
- Group by Review.Vendor__c
3. Ability to filter through search Ryan Schierholz
- I assume, if searchTerm is passed to the fetchData(), then user want to search. If empty string is passed, we display all super categories without filter.
Please mark this as solved if it helped you.
All Answers
1. Object Api Names
- Super_Category__c
- Category__c
- Review__c
2. Reference Field names
- FieldName: Category__c.Super_Category__c | Rlationship name: Category.Super_Category__r
- FieldName: Review__c.Category__c | Rlationship name: Review__c.Category__r
3. You have apex method and wrapper class like below:
4. Call this apex CategoriesController.fetchData() from lwc and store the response in var and console it. You should get the same structure (Only extra thing is that I have kept Id in every wrapper instance)
Please let me know if you face any issues. Please correct if any typos.
I tried removing keySet(), but then got a different error:
Anymore insight you have is VERY much appreciated. Thank you, Nayana.
Monday my morning, I will try to check. Sorry about that.
-- Assuming we need only super categories having atleast one Categorys.Reviews
2. If there are more than one review for a Vendor in a category, only show the Vendor/Review once, but show the number of 'duplicates'.
- Group by Review.Vendor__c
3. Ability to filter through search Ryan Schierholz
- I assume, if searchTerm is passed to the fetchData(), then user want to search. If empty string is passed, we display all super categories without filter.
Please mark this as solved if it helped you.
Thank you for #2. I can show the dupeCount on the Lightning web component. However, I thought I could use that number to return a Boolean of whether there are duplicates or not. I only want to show the number if its greater than 1.
So, at the bottom of the Review class I use the code:
and then reference the hasDupes in the LWC. However, it's always showing as false, even when the number shows as "2"
Wondering what I could be missing or how to hide the "1" but show the "2"
Then initialize the hasDupes to false in the wrapper class constructor