Ant-design: Selección de árbol

Creado en 16 may. 2016  ·  3Comentarios  ·  Fuente: ant-design/ant-design

Cuando Tree obtiene el elemento seleccionado, ¿puede obtener todo el nodo principal del elemento seleccionado y el nodo principal del nodo principal, como un menú de tres niveles, después de seleccionar el nodo hoja del último nivel, los primeros 2 elementos de el artículo seleccionado no se puede obtener

Comentario más útil

let sel = [];
function findPath(selected, children, parent = { root: true }) {
  for (var i = 0; i < children.length; i++) {
    const item = children[i];
    if (selected === item.key) {
      sel.push(item);
      return;
    }
    if (item.children) {
      findPath(selected, item.children, item);
      if (sel.length) {
        sel.push(item);
        return;
      }
    }
  }
}

Todos 3 comentarios

let sel = [];
function findPath(selected, children, parent = { root: true }) {
  for (var i = 0; i < children.length; i++) {
    const item = children[i];
    if (selected === item.key) {
      sel.push(item);
      return;
    }
    if (item.children) {
      findPath(selected, item.children, item);
      if (sel.length) {
        sel.push(item);
        return;
      }
    }
  }
}

¿Se ha resuelto el problema?Cerrar primero

Este hilo se ha bloqueado automáticamente porque no ha tenido actividad reciente. Abra un nuevo problema para errores relacionados y enlace a comentarios relevantes en este hilo.

¿Fue útil esta página
0 / 5 - 0 calificaciones