ztree 數據格式及其配置


ztree的數據格式可以有兩種

一、children層級

如下:

復制代碼
[{
    name: "企業基本信息",
    parentId: "0",
    id: "04",
    children: [
      {
        name: "minsfasf信息",
        parentId: "04",
        id: "040",
      },
    ],
  }]
復制代碼

二、pId平級

復制代碼
{
    name: "企業基本信息",
    parentId: "0",
    id: "04",
  },
  {
    name: "工商信息",
    parentId: "04",
    id: "040",
  },
  {
    name: "注冊信息",
    parentId: "040",
    id: "0400",
  },
  {
    name: "股東信息",
    parentId: "040",
    id: "0401",
  },
  {
    name: "高管信息",
    parentId: "040",
    id: "0402",
  }
復制代碼

字段名稱都可以修改,同時要在配置信息中做修改。

三、基本配置

復制代碼
setting: {
        treeId: "id", // 節點id
        view: {
          showIcon: false,
          addHoverDom: this.editEnable ? this.addHoverDom : "",
          removeHoverDom: this.editEnable ? this.removeHoverDom : "",
          selectedMulti: false,
        },
        edit: {
          enable: this.editEnable,
          showRemoveBtn: true,
          showRenameBtn: true,
          removeTitle: "刪除",
          renameTitle: "重命名",
          // editNameSelectAll: true,
        },
        data: {
          key: {
            name: "name", //
            children: "children", //zTree 節點數據中保存子節點數據的屬性名稱。
            isParent: "isParent", //zTree 節點數據保存節點是否為父節點的屬性名稱。
          },
          keep: {
            parent: true,
            leaf: true,
          },
          simpleData: {
            enable: true, // 顯示層級
            idKey: "id", // 唯一標識的屬性名稱
            pIdKey: "parentId", // 父節點唯一標識的屬性名稱
            // idPKey: "pId",
            rootPId: 0, // 修正根節點父節點數據
          },
        },
        callback: {
          onClick: this.zTreeOnClick,
          onRename: this.zTreeOnRename,
        },
      },
復制代碼

效果:

 原創作者:https://www.cnblogs.com/lyt0207/p/13533913.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM