1
0

json_editor_documentation.py 815 B

12345678910111213141516171819202122232425262728
  1. from nicegui import ui
  2. from . import doc
  3. @doc.demo(ui.json_editor)
  4. def main_demo() -> None:
  5. json = {
  6. 'array': [1, 2, 3],
  7. 'boolean': True,
  8. 'color': '#82b92c',
  9. None: None,
  10. 'number': 123,
  11. 'object': {
  12. 'a': 'b',
  13. 'c': 'd',
  14. },
  15. 'time': 1575599819000,
  16. 'string': 'Hello World',
  17. }
  18. editor = ui.json_editor({'content': {'json': json}},
  19. on_select=lambda e: ui.notify(f'Select: {e}'),
  20. on_change=lambda e: ui.notify(f'Change: {e}'))
  21. ui.button('Expand All', on_click=lambda: editor.call_editor_method('expand', 'path => true'))
  22. ui.button('Collapse All', on_click=lambda: editor.call_editor_method('expand', 'path => false'))
  23. doc.reference(ui.json_editor)