feat(utile): replaceChildNode找不多目标不报错

This commit is contained in:
roymondchen 2025-07-22 20:16:37 +08:00
parent 00cf312a91
commit 2605011df4

View File

@ -380,8 +380,15 @@ export const replaceChildNode = (newNode: MNode, data?: MNode[], parentId?: Id):
parent = getNodePath(parentId, data).pop(); parent = getNodePath(parentId, data).pop();
} }
if (!node) throw new Error('未找到目标节点'); if (!node) {
if (!parent) throw new Error('未找到父节点'); console.warn(`未找到目标节点(${newNode.id})`);
return;
}
if (!parent) {
console.warn(`未找到父节点(${newNode.id})`);
return;
}
const index = parent.items?.findIndex((child: MNode) => child.id === node.id); const index = parent.items?.findIndex((child: MNode) => child.id === node.id);
parent.items.splice(index, 1, newNode); parent.items.splice(index, 1, newNode);