export function renameChildKey(tree, orign_childKey, new_childKey) {
tree.forEach(item => {
if (item[orign_childKey]) {
item[new_childKey] = item[orign_childKey];
delete item[orign_childKey];
}
if (item[new_childKey] && item[new_childKey].length > 0) {
renameChildKey(item[new_childKey], orign_childKey, new_childKey);
}
})
return tree;
}
JS给树形结构一个的childkey属性重命名
这篇文章介绍了一个名为`renameChildKey`的JavaScript函数,用于遍历树形数据结构,递归地将指定的原始子键名替换为目标子键名,并删除原始键。该技术在处理复杂对象时非常实用,尤其在IT技术中的数据处理和转换场景。
摘要由CSDN通过智能技术生成