修改前
// 修改树形结构的键值 把items替换为children
function changeId(objAry, key, newkey) {
if (objAry != null) {
objAry.forEach((item) => {
Object.assign(item, {
[newkey]: item[key],
});
delete item[key];
changeId(item.children, key, newkey);
});
}
}
//items是之前的键 children是要修改后的键 data是树形结构的数据(数组)
changeId(data, "items", "children");
修改后