Replies: 1 comment
-
You might find this discussion and the Dynamic widgets section of the Tutorial useful.
You can add new widgets while the app is running by calling class ItemsList(Container):
items = reactive([], layout=True)
pressed_count = reactive(0, layout=True)
def compose(self) -> ComposeResult:
yield Static(f"ItemsList {self.pressed_count}")
for item in self.items:
yield Static(item)
def watch_items(self) -> None:
if self.items: # Avoids IndexError if list is empty
new_item = self.items[-1]
self.mount(Static(new_item)) P.S. You might also want to look into the ListView widget - this might make your life easier as it has a convenient |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I am trying to create a hierarchy list by passing value through reactive. Here is a simplified version of the code:
If rendered as:
My goal is to append items to the
ItemsList
after pressed theAdd item
button. However, it seems like the updated reactive values in theItemsList
never trigger re-rendering.I also tried to use a Static widget to simulate similar usage, however, seems like it works as the
render
method has been called when updating the reactive property.I think my current approach is incorrect, but I didn't find any existing examples show such usage. Please let me know what's the expected way for updating value from top to down. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions