通过该方法可以实现树结构。 function convertToTree(data) { const tree = []; data.forEach(items => { let currentNode = tree; items.forEach((item, index) => { const existingNode = currentNode.find(node => node.name === item); if (existingNode) { currentNode = existingNode.children; } else { const newNode = { code: '', name: item, children: [] }; currentNode.push(newNode); currentNode = newNode.children; } if (index === items.length - 1) { currentNode.code = items[0]; } }); }); return tree; } const originalData = [['浙江省','杭州市','余杭区'],['江苏省','南京市']]; console.log(convertToTree(originalData)); 但是实现了也没有办法获取code码啊。。。应该让后端修改返回的数据格式。或者前端自己使用静态文件来使用数据,。