Tree

Muestra un conjunto de datos jerárquicos.

Uso básico

Estructura básica de árbol.

Seleccionable

Usado para la selección de nodos.

Este ejemplo también muestra como cargar los datos de forma asíncrona.

WARNING

When using show-checkbox, since check-on-click-leaf is true by default, last tree children's can be checked by clicking their nodes.

Nodos hoja en modo perezoso (lazy load)

Los datos de un nodo no son cargados hasta que no es pinchado, así que el árbol no puede predecir si es una hoja. Por eso a cada nodo se le añade el botón de desplegar, y si el nodo es una hoja el botón desaparecerá al pinchar en él. También puede decirle al árbol que el nodo es una hoja de antemano, y así evita que muestre el botón de desplegar.

Lazy loading multiple times 2.6.3

When lazily loading node data remotely, lazy loading may sometimes fail. In this case, you can call reject to keep the node status as is and allow remote loading to continue.

Checkbox desactivados

El checkbox de un nodo se puede poner como desactivado.

En el ejemplo, la propiedad disabled se declara en defaultProps, y algunos nodos se ponen como disabled:true. Los checkboxes correspondientes son desactivados y no se pueden pinchar.

Desplegado o seleccionado por defecto

Los nodos pueden estar desplegados o seleccionados por defecto.

Utilice default-expanded-keys y default-checked-keys para establecer los nodos desplegados y seleccionados respectivamente. Tenga en cuenta que para que funcione es necesario que tengan node-key. Su valor es el nombre de una clave en el objeto data, y el valor de la clave debe ser único en todo el árbol.

Level one 2
Level one 3

Seleccionando nodos

Este ejemplo muestra como establecer y leer nodos seleccionados. Esto se puede hacer por nodos o por claves. Si lo hace por claves el atributo node-key es necesario.

Level one 1
Level two 1-1
Level three 1-1-1
Level three 1-1-2
Level one 2
Level two 2-1
Level two 2-2
Level one 3
Level two 3-1
Level two 3-2

Contenido personalizado en los nodos

El contenido de los nodos puede ser personalizado, así que puede añadir iconos y botones a su gusto.

Hay dos maneras de personalizar la plantilla para los nodos de árbol: render-content y scoped slot. Utilice render-content para asignar una función de renderizado que devuelve el contenido del árbol de nodos. Mire la documentación de node para una introducción detallada a las funciones de renderizado. Si prefiere scoped slot, tendrá acceso a los nodos y datos en el ámbito de aplicación, representando el objeto TreeNode y los datos del nodo actual respectivamente. Ten en cuenta que la demo de render-content no puede ejecutarse en JSFiddle porque no soporta la sintaxis JSX. En un proyecto real render-content funcionará si las dependencias son configuradas correctamente.

Using render-content

Level one 1
Level two 1-1
Level three 1-1-1
Level three 1-1-2
Level one 2
Level two 2-1
Level two 2-2
Level one 3
Level two 3-1
Level two 3-2

Using scoped slot

Level one 1
Level two 1-1
Level three 1-1-1
Level three 1-1-2
Level one 2
Level two 2-1
Level two 2-2
Level one 3
Level two 3-1
Level two 3-2

Clase de nodo personalizado

La clase de nodos de árbol puede ser personalizada

. Usa props.class para construir un nombre de clase de nodos.

Level one 1
Level two 1-1
Level three 1-1-1
Level three 1-1-2
Level one 2
Level two 2-1
Level two 2-2
Level one 3
Level two 3-1
Level two 3-2

Filtrado de nodos

Los nodos del árbol se pueden filtrar.

Invoque el método filter de la instancia de Tree para filtrar los nodos. Su parámetro es la palabra de filtrado. Tenga en cuenta que para que funcione es necesario filter-node-method, y su valor el método de filtrado.

Level one 1
Level two 1-1
Level three 1-1-1
Level three 1-1-2
Level one 2
Level two 2-1
Level two 2-2
Level one 3
Level two 3-1
Level two 3-2

Acordeón

Solo puede ser expandido un nodo del mismo nivel a la vez.

Arrastrable

Puede arrastrar y soltar nodos de Tree añadiendo un atributo draggable .

Level one 1
Level two 1-1
Level three 1-1-1
Level one 2
Level two 2-1
Level three 2-1-1
Level two 2-2
Level three 2-2-1
Level one 3
Level two 3-1
Level three 3-1-1
Level two 3-2
Level three 3-2-1

Atributos

NombreDescripciónTipoPor defecto
dataDatos del árbolobject
empty-textTexto a mostrar cuando data es voidstring
node-keyIdentificador único en todo el árbol para los nodosstring
propsOpciones de configuraciónobject
render-after-expandsi se mostrarán los nodos hijo sólo después de que se desglose por primera vez un nodo padrebooleantrue
loadMétodo para cargar los datos de subárbolesFunction
render-contentFunción de renderizado para los nodosFunction
highlight-currentSi el nodo actual está resaltadobooleanfalse
default-expand-allExpandir todos los nodos por defectobooleanfalse
expand-on-click-nodeSi expandir o contraer un nodo al pincharlo, si es false solo se hará al pinchar en la flechabooleantrue
check-on-click-nodeSi es false, el nodo sólo se puede marcar o desmarcar haciendo clic en la casilla de verificación.booleanfalse
check-on-click-leaf 2.9.6whether to check or uncheck node when clicking on leaf node (last children).booleantrue
auto-expand-parentExpandir un nodo padre si el hijo está seleccionadobooleantrue
default-expanded-keysArray de claves de los nodos expandidos inicialmenteobject
show-checkboxSi un nodo es seleccionablebooleanfalse
check-strictlyEl estado de selección de un nodo no afecta a sus padres o hijos, cuando show-checkbox es truebooleanfalse
default-checked-keysArray con claves de los nodos seleccionados inicialmenteobject
current-node-keyla clave del nodo inicialmente seleccionadostring / number
filter-node-methodesta función se ejecutará antes de arrastrar un nodo. si devuelve false, el nodo no puede ser arrastrado.Function
accordionSi solo un nodo de cada nivel puede expandirse a la vezbooleanfalse
indentIndentación horizontal de los nodos en niveles adyacentes, en pixelesnumber18
iconcomponente de icono de nodo de árbol personalizadostring / Component
lazysi se trata de un nodo de hoja lazy load, utilizado con el atributo loadbooleanfalse
draggablesi se habilita la función de drag & drop en los nodosbooleanfalse
allow-dragesta función se ejecutará antes de arrastrar un nodo. Si se devuelve false, el nodo no puede ser arrastradoFunction
allow-dropesta función se ejecutará al arrastrar y soltar un nodo. si devuelve false, el nodo arrastrando no se puede soltar en el nodo destino. type tiene tres valores posibles: 'prev' (insertar el nodo de arrastre antes del nodo de destino), 'inner' (insertar el nodo de arrastre en el nodo de destino) y 'next' (insertar el nodo de arrastre después del nodo de destino)Function

props

AtributosDescripciónTipoPor defecto
labelEspecifica que clave del objecto nodo se utilizará como labelstring / Function
childrenEspecifica que objeto del nodo se utiliza como subárbolstring
disabledEspecifica si el nodo es una hoja, sólo funciona cuando lazy load está activadostring / Function
isLeafelimina un nodo, solo funciona si node-key está asignadostring / Function
classnombre de clase de nodo personalizadostring / Function

Método

Tree has the following method, which returns the currently selected array of nodes.

MethodDescripciónParámetros
filterfilter all tree nodes, filtered nodes will be hiddenAccept a parameter which will be used as first parameter for filter-node-method
updateKeyChildrenset new data to node, only works when node-key is assigned(key, data) Accept two parameters: 1. key of node 2. new data
getCheckedNodesIf the node can be selected (show-checkbox is true), it returns the currently selected array of nodes(leafOnly, includeHalfChecked) Accept two boolean type parameters: 1. default value is false. If the parameter is true, it only returns the currently selected array of sub-nodes. 2. default value is false. If the parameter is true, the return value contains halfchecked nodes
setCheckedNodesset certain nodes to be checked, only works when node-key is assignedan array of nodes to be checked
getCheckedKeysIf the node can be selected (show-checkbox is true), it returns the currently selected array of node's keys(leafOnly) Accept a boolean type parameter whose default value is false. If the parameter is true, it only returns the currently selected array of sub-nodes.
setCheckedKeysset certain nodes to be checked, only works when node-key is assigned(keys, leafOnly) Accept two parameters: 1. an array of node's keys to be checked 2. a boolean parameter. If set to true, only the checked status of leaf nodes will be set. The default value is false.
setCheckedset node to be checked or not, only works when node-key is assigned(key/data, checked, deep) Accept three parameters: 1. node's key or data to be checked 2. a boolean typed parameter indicating checked or not. 3. a boolean typed parameter indicating deep or not.
getHalfCheckedNodesIf the node can be selected (show-checkbox is true), it returns the currently half selected array of nodes
getHalfCheckedKeysIf the node can be selected (show-checkbox is true), it returns the currently half selected array of node's keys
getCurrentKeyreturn the highlight node's key (null if no node is highlighted)
getCurrentNodereturn the highlight node's data (null if no node is highlighted)
setCurrentKeyset highlighted node by key, only works when node-key is assigned(key, shouldAutoExpandParent=true) 1. the node's key to be highlighted. If null, cancel the currently highlighted node 2. whether to automatically expand parent node
setCurrentNodeset highlighted node, only works when node-key is assigned(node, shouldAutoExpandParent=true) 1. the node to be highlighted 2. whether to automatically expand parent node
getNodeget node by data or key(data) the node's data or key
removeremove a node, only works when node-key is assigned(data) the node's data or node to be deleted
appendappend a child node to a given node in the tree(data, parentNode) 1. child node's data to be appended 2. parent node's data, key or node
insertBeforeinsert a node before a given node in the tree(data, refNode) 1. node's data to be inserted 2. reference node's data, key or node
insertAfterinsert a node after a given node in the tree(data, refNode) 1. node's data to be inserted 2. reference node's data, key or node

Eventos

NombreDescripciónParameters
node-clicktriggers when a node is clickedfour parameters: node object corresponding to the node clicked, node property of TreeNode, TreeNode itself, event object
node-contextmenutriggers when a node is clicked by right buttonfour parameters: event, node object corresponding to the node clicked, node property of TreeNode, TreeNode itself
check-changetriggers when the selected state of the node changesthree parameters: node object corresponding to the node whose selected state is changed, whether the node is selected, whether node's subtree has selected nodes
checktriggers after clicking the checkbox of a nodetwo parameters: node object corresponding to the node that is checked / unchecked, tree checked status object which has four props: checkedNodes, checkedKeys, halfCheckedNodes, halfCheckedKeys
current-changetriggers when current node changestwo parameters: node object corresponding to the current node, node property of TreeNode
node-expandtriggers when current node openthree parameters: node object corresponding to the node opened, node property of TreeNode, TreeNode itself
node-collapsetriggers when current node closethree parameters: node object corresponding to the node closed, node property of TreeNode, TreeNode itself
node-drag-starttriggers when dragging startstwo parameters: node object corresponding to the dragging node, event.
node-drag-entertriggers when the dragging node enters another nodethree parameters: node object corresponding to the dragging node, node object corresponding to the entering node, event.
node-drag-leavetriggers when the dragging node leaves a nodethree parameters: node object corresponding to the dragging node, node object corresponding to the leaving node, event.
node-drag-overtriggers when dragging over a node (like mouseover event)three parameters: node object corresponding to the dragging node, node object corresponding to the dragging over node, event.
node-drag-endtriggers when dragging endsfour parameters: node object corresponding to the dragging node, node object corresponding to the dragging end node (may be undefined), node drop type (before / after / inner), event.
node-droptriggers after the dragging node is droppedfour parameters: node object corresponding to the dragging node, node object corresponding to the dropped node, node drop type (before / after / inner), event.

Slots

NameDescription
Custom content for tree nodes. The scope parameter is { node, data }
empty 2.3.4empty you can customize content when data is empty.

Fuente

ComponentesStyleDocumentación

Contribuidores