Show items list inside other item list

So i have two lists one inside the other

One list is for tasks
the other is for tasks activities

one task can have many task activities

each task is one item from the tasklist

each activity is one item from task activity list

so what i want to do is to show the activities from the task i click only, what happens now is that when i click on the task name to show the activities by using a variable “showActivities”, it shows all the activities from all tasks, i want to show only the task_activities from the task item i click, how do i do this?

I made it work by adding an isOpen (boolean) column to the Tasks collection.

In task_activities_list, I check task.data.isOpen to determine whether to display the activities.

When clicking on a task name, I toggle isOpen between true and false and update the Tasks collection isOpen column accordingly.

It works, but is this the best approach? Can I achieve this without relying on the database for the check?