mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-09-19 21:06:06 +08:00
feat(utile): replaceChildNode找不多目标不报错
This commit is contained in:
parent
00cf312a91
commit
2605011df4
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user