JavaScript递归树,修改或添加属性值
let index = 0; const mapTree = (org) => { const haveChildren = Array.isArray(org.children) && org.children.length > 0; index++; return { ...org, sortLabel: index, children: haveChildren ? org.children.map(child => mapTree(child)) : null, }; }; const list = listTree.map(org => mapTree(org));

浙公网安备 33010602011771号