container.remove(last_element) gives KeyError #677
-
Hey, i want to remove elements in a container, that get dynamically created. code: def place_submitted_search_values(container):
search_values = get_checked_results()
with container:
for item in search_values:
with ui.row().classes("w-full") as row:
ui.label(text=item)
ui.button("", on_click=lambda: container.remove(row)).props("icon=delete") expectation: full traceback: Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\nicegui\events.py", line 281, in handle_event
result = handler() if no_arguments else handler(arguments)
^^^^^^^^^
File "c:\Users\User\listitem.py", line 20, in <lambda>
ui.button("", on_click=lambda: container.remove(row)).props("icon=delete")
^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\AppData\Local\Programs\Python\Python311\Lib\site-packages\nicegui\element.py", line 291, in remove
del self.client.elements[element.id]
~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 349 |
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
Mar 31, 2023
Replies: 1 comment 1 reply
-
See this discussion about capturing values in lambda statements: #471 This way you can fix your button: ui.button(on_click=lambda e, row=row: container.remove(row)) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
HilkopterBob
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See this discussion about capturing values in lambda statements: #471
This way you can fix your button: