/** * @description 生成树结构 * @param {Array} data - 数据 * @param {*} parentId * @returns 数结构,数据包含title value children */ function loopTree(data,parentId) { if (!data || data.length === 0) return []; const arr = data.map((item) => { const it = { title: item.title, key: item.key, value: item.value, parentId, ...item, }; if (item.children) { it.children = loopTree(item.children, item.key); } return it; }) || []; return arr; }
生成树结构
最新推荐文章于 2024-07-12 16:27:40 发布