how to update a variable #3642
-
Hi, I dont quite understand why I am not seeing the 'increases' when I open the the data in a json_editor? Can someone please tell me what am I missing here? How can I update the nicedict variable and use the updated version "later" in other elements? from nicegui import ui
nicedict = {"a": 1, "b": 2}
def updatenicedict():
nicedict['a'] = nicedict['a'] + 1
ui.label().bind_text_from(nicedict, 'a', backward=lambda a: f'a: {a}')
ui.button("increase", on_click=lambda: updatenicedict())
with ui.dialog() as dialog:
ui.json_editor({'content': {'json': nicedict}})
ui.button('show tha data', on_click=dialog.open)
ui.run(title='why') Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
Aug 30, 2024
Replies: 2 comments 2 replies
-
it is same as #2149 . nicedict = {"a": 1, "b": 2}
def updatenicedict():
nicedict['a'] = nicedict['a'] + 1
ui.label().bind_text_from(nicedict, 'a', backward=lambda a: f'a: {a}')
ui.button("increase", on_click=lambda: updatenicedict())
with ui.dialog() as dialog:
je = ui.json_editor({'content': {'json': nicedict}})
ui.button('show tha data', on_click=lambda :(je.update(),dialog.open()))
ui.button('print',on_click=lambda : ui.notify(je._props)) |
Beta Was this translation helpful? Give feedback.
1 reply
-
The content of the JSON editor isn't bound to the dictionary. Therefore you need to call nicedict = {'a': 1, 'b': 2}
def updatenicedict():
nicedict['a'] = nicedict['a'] + 1
editor.update()
ui.label().bind_text_from(nicedict, 'a', backward=lambda a: f'a: {a}')
ui.button('increase', on_click=lambda: updatenicedict())
editor = ui.json_editor({'content': {'json': nicedict}}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GeorgiT-HI
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The content of the JSON editor isn't bound to the dictionary. Therefore you need to call
update()
to update the UI: