Issue removing data from element children

I have an element in my app that exists to contain a list of tooltips for elements defined elsewhere.

dhtml.P(children=[], id='Tooltips'),

I recently added the option to delete the element the tooltip is attached to and, for garbage cleaning purposes, remove the associated tooltips.

#The output arg in the callback declaration for the above element
Output('TimelineComments', 'data', allow_duplicate=True)],
...
#The state arg in the callback that retrieves the existing tooltip list
State('Tooltips', 'children')
...
    toPop = []
    for i in range(0, len(tooltips)):
        if tooltips[i]['props']['target']['tier'] == SelectedTier:     #This condition creates a list of tooltips to delete
            toPop.append(i)
        elif tooltips[i]['props']['target']['tier'] > SelectedTier:    #This condition amends the id of some other tooltips (not sure if this is related)
            tooltips[i]['props']['target']['tier'] = tooltips[i]['props']['target']['tier']-1
    for i in range(0, len(toPop)):    #Then delete the tooltips at the indices in the array
        del tooltips[i]

I’ve been encountering an error after i try to handle this list in following functions where the list of tooltips has some non-tooltip items appended. See Photo from debug

Anyone know why this is happening and how to stop it?

Hello @DwilliamsTM,

Have you tried using Patch() instead? It seems like you are close to utilizing it with the actions you are performing.

I suppose I could use patch. Any idea why this is happening though?

What are you returning?

I take the original list of children, amend the list, and return the list

Yeah… id recommend using Patch:

It so much easier, and you dont have to mess with sending the whole children up to the server each time.

As far as why its leaving something, who knows. Haha.

1 Like