1
0

json_editor_documentation.py 994 B

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