El backend devuelve la estructura List y el frontend recorre los datos del árbol ensamblados en el elemento

Datos devueltos en segundo plano: se puede utilizar un bean o mapa personalizado

{   "msg": "操作 成功",   "result": [     {       "drop": false,       "clickHandler": false,       "gislefturl": "",       "icon": "",       "existed": false,       "routeName ":" ",       " gis ": falso,       " comprobado ": falso,       " clickExpand ": falso,       " arrastrar ": falso,       " id ":" 37060700 ",       " texto ":" ",       " nocheck ": falso,       "chkDisabled": falso,       "iconOpen": "",       "isParent": false,       "manager": "",       "index": "",       "oldParentId": "",       "haga clic en": "",       "iconClose": "",
























      "parentId": "37060000",
      "url": "",
      "target": "",
      "if_check": "0",
      "phone": "",
      "name": "牟平",
      "infoMap": { },
      "menuType": "",
      "open": false,
      "desc": ""
    },
    {       "drop": false,       "clickHandler": false,       "gislefturl": "",       "icon": "",       "existido": falso,       "routeName": "",       "gis": falso,       "comprobado": falso,       "clickExpand": falso,       "arrastrar": falso,       "id": "37060701",       "texto": "",       "nocheck": falso,













      "chkDisabled": false,
      "iconOpen": "",
      "isParent": false,
      "manager": "",
      "index": "",
      "oldParentId": "",
      "clic": "",
      "iconClose" : "",
      "parentId": "37060700",
      "url": "",
      "target": "",
      "if_check": "0",
      "phone": "",
      "name": "办公室",
      " infoMap ": {},
      " menuType ":" ",
      " abrir ":false,
      "desc": ""
    },
    {       "drop": false,       "clickHandler": false,       "gislefturl": "",       "icon": "",       "existido": falso,





      "routeName": "",
      "gis": falso,
      "comprobado": falso,
      "clickExpand": falso,
      "arrastrar": falso,
      "id": "37060702",
      "texto": "",
      "nocheck": false,
      "chkDisabled": false,
      "iconOpen": "",
      "isParent": false,
      "manager": "",
      "index": "",
      "oldParentId": "",
      "clic": "",
      " iconClose ":" ",
      " parentId ":" 37060700 ",
      "url": "",
      "target": "",
      "if_check": "0",
      "phone": "",
      "name": "工程 管理 科",
      "infoMap": {},
      "menuType": "",
      "open": false,
      "desc": ""
    },
    {       "drop": false,       "clickHandler": false,       "gislefturl": "",       "icon": "",       "existed": false,       "routeName" : "",       "gis": falso,       "comprobado": falso,       "clickExpand": falso,       "arrastrar": falso,       "id": "37060703",       "texto": "",       "nocheck": falso,       " chkDisabled ": false,       " iconOpen ":" ",       "isParent": false,       "manager": "",       "index": "",       "oldParentId": "",       "haga clic en": "",       "iconClose": "",





















      "parentId": "37060700",
      "url": "",
      "target": "",
      "if_check": "0",
      "phone": "",
      "name": "计划 财务科",
      "infoMap" : {},
      "menuType": "",
      "abrir": falso,
      "desc": ""
    },
 
  ],
  "código": 0
}

 

Método de visualización de la recepción:

flap2tree (arr, key = 'id', parentKey = 'pid', rootFilter) {

sea ​​rs = [];

dejar mapObj = {};

dejar copyArr = [];

arr.forEach ((elemento) => {

let newItem = {... item};

copyArr.push (newItem);

mapObj [item [key]] = newItem;

});

copyArr.forEach ((elemento) => {

let pid = item [parentKey];

let parent = null;

si (pid) {

padre = mapObj [pid];

if (padre) {

if (! parent.children) {

parent.children = [];

}

parent.children.push (elemento);

}

}

if (! parent) {

rs.push (elemento);

}

mapObj [elemento [clave]] = elemento;

});

if (rootFilter) {

rs = rs.filter (rootFilter);

}

return rs;

}

Supongo que te gusta

Origin blog.csdn.net/CarryBest/article/details/94629686
Recomendado
Clasificación