Browse Source

Merge pull request #1239 from zauberzeug/tree_expand

add demo for tree expansion/collapse
Falko Schindler 1 năm trước cách đây
mục cha
commit
c63d65b676
1 tập tin đã thay đổi với 21 bổ sung0 xóa
  1. 21 0
      website/more_documentation/tree_documentation.py

+ 21 - 0
website/more_documentation/tree_documentation.py

@@ -33,3 +33,24 @@ def more() -> None:
         tree.add_slot('default-body', '''
             <span :props="props">Description: "{{ props.node.description }}"</span>
         ''')
+
+    @text_demo('Expand programmatically', '''
+        The tree can be expanded programmatically by modifying the "expanded" prop.
+    ''')
+    def expand_programmatically():
+        from typing import List
+
+        def expand(node_ids: List[str]) -> None:
+            t._props['expanded'] = node_ids
+            t.update()
+
+        with ui.row():
+            ui.button('all', on_click=lambda: expand(['A', 'B']))
+            ui.button('A', on_click=lambda: expand(['A']))
+            ui.button('B', on_click=lambda: expand(['B']))
+            ui.button('none', on_click=lambda: expand([]))
+
+        t = ui.tree([
+            {'id': 'A', 'children': [{'id': 'A1'}, {'id': 'A2'}]},
+            {'id': 'B', 'children': [{'id': 'B1'}, {'id': 'B2'}]},
+        ], label_key='id')