递归查找

const findNode = function f(data: TreeDataNode[], key: string | number): TreeDataNode | undefined {
  if (!data || !key) return undefined;
  for (let i = 0, len = data.length; i < len; i++) {
    const curr = data[i];
    if (curr.key === key) return curr;
    if (curr.children) {
      const node = f(curr.children, key);
      if (node) return node;
    }
  }
  return undefined;
};
最近修改时间:2024-08-14 06:54:07