Issue with dynamically added resources with data-sly-resource
I have a custom "container" and "row" component. On the container touch UI dialog, an author can select the number of rows they want to add. In the HTL, I am using data-sly-list for the loop through, and inside the loop, I am using data-sly-resource to add the number of rows. This works great when I am increasing the number of rows for example from 1 to 3. So for each row, it creates child nodes under the container component.
The issue we are seeing is that when we decrease the number from 3 to 1, it's not deleting the child nodes.
For example, let's say I entered 3 in the number of rows field in the container component and submit the dialog; it will create the nodes like below.
container
- row1
- row2
- row3
Now if I open the container dialog again and change the number of rows to 1, it still keeps the row2 and row3 nodes that were created previously. It doesn't delete it. It's not breaking anything as based on the logic it will only render the row1 in the final output, but those nodes are still there that are not being used.
Is there a way to delete those dynamically created nodes every time the value is updated?


