Vue list数据转化为树结构

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Vue list数据转化为树结构

~疆   2022-06-03 我要评论

下载

cnpm i -S array-to-tree

引入

import arrayToTree from "array-to-tree";

使用

    const pidData = [
      { name: "aa", id: "1", pid: null },
      { name: "bb", id: 2, pid: 1 },
      { name: "cc", id: 3, pid: "" },
      { name: "dd", id: 4, pid: 3 },
      { name: "ee", id: 5, pid: "3" },
    ];
    const result = arrayToTree(pidData, {
      parentProperty: "pid",
      customID: "id",
      childrenProperty: "children",
    });
    console.log(result);

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们