Vue將將後端返回的list數據轉化為樹結構的實現

下載

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);

到此這篇關於Vue將將後端返回的list數據轉化為樹結構的文章就介紹到這瞭,更多相關Vue將將後端返回的list數據轉化為樹結構內容請搜索LevelAH以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持LevelAH!

推薦閱讀: