mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 18:31:06 +00:00
Fix that toHierarchy couldn't be found. Updated docs and test.
This commit is contained in:
parent
491b319078
commit
048c10a6ab
11 changed files with 70 additions and 47 deletions
|
@ -17777,18 +17777,6 @@
|
|||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": true
|
||||
},
|
||||
{
|
||||
"name": "nodesFlat",
|
||||
"kind": "let",
|
||||
"description": "Provide a flat array of nodes to render",
|
||||
"type": "Array<TreeNode & {pid?: any}>",
|
||||
"value": "[]",
|
||||
"isFunction": false,
|
||||
"isFunctionDeclaration": false,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
|
@ -17887,6 +17875,18 @@
|
|||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "toHierarchy",
|
||||
"kind": "function",
|
||||
"description": "Create a nested array from a flat array",
|
||||
"type": "(flatArray: TreeNode[] & { pid?: any }[]) => TreeNode[]",
|
||||
"value": "() => {\n return th(flatArray);\n}",
|
||||
"isFunction": true,
|
||||
"isFunctionDeclaration": true,
|
||||
"isRequired": false,
|
||||
"constant": false,
|
||||
"reactive": false
|
||||
},
|
||||
{
|
||||
"name": "expandNodes",
|
||||
"kind": "function",
|
||||
|
|
|
@ -58,14 +58,6 @@ To render a node with an icon, define an `icon` property with a Carbon Svelte ic
|
|||
|
||||
<FileSource src="/framed/TreeView/TreeViewIcons" />
|
||||
|
||||
## Flat data structure
|
||||
|
||||
Provide a flat data structure through the `nodesFlat` property. Child object needs to have a `pid` property
|
||||
to reference its parent. Optionally the key for the parent can be provided.
|
||||
When no parent id is available the object is assumed to be at the root of the tree.
|
||||
|
||||
<FileSource src="/framed/TreeView/TreeViewFlatArray" />
|
||||
|
||||
## Initial expanded nodes
|
||||
|
||||
Expanded nodes can be set using `expandedIds`.
|
||||
|
@ -116,3 +108,13 @@ Use the `TreeView.showNode` method to show a specific node.
|
|||
If a matching node is found, it will be expanded, selected, and focused.
|
||||
|
||||
<FileSource src="/framed/TreeView/TreeViewShowNode" />
|
||||
|
||||
## Flat data structure
|
||||
|
||||
Use the `toHierarchy` method to provide a flat data structure to the `nodes` property.
|
||||
|
||||
This method will transform a flat array of objects into the hierarchical array as expected by `nodes`.
|
||||
The child objects in the flat array need to have a `pid` property to reference its parent.
|
||||
When `pid` is not provided the object is assumed to be at the root of the tree.
|
||||
|
||||
<FileSource src="/framed/TreeView/TreeViewFlatArray" />
|
Loading…
Add table
Add a link
Reference in a new issue