I have a db table for categories where a category can be a sub-category of a category in the same table. For example:
category_id | category_name | parent_id |
---|---|---|
1 | Vocabulary | nil |
2 | Animals | 1 |
3 | Food | 1 |
4 | Grammar | nil |
5 | Mammals | 2 |
I want to show this list on category creation form as a dropdown to select parent category.
Something like,
Vocabulary
- Animals
- Mammals
- Food
Grammar
How can I render the list in this way? Or is there a better way to handle this requirement?
I am not using LiveView for this project.