Fix:修复删除含有子节点的节点时,data_change_detail事件报错

This commit is contained in:
街角小林 2024-01-11 17:55:10 +08:00
parent cd7936a50b
commit b5cfca848a

View File

@ -177,6 +177,7 @@ class Command {
// 派发思维导图更新明细事件 // 派发思维导图更新明细事件
emitDataUpdatesEvent(lastData, data) { emitDataUpdatesEvent(lastData, data) {
try {
// 如果data_change_detail没有监听者那么不进行计算节省性能 // 如果data_change_detail没有监听者那么不进行计算节省性能
const eventName = 'data_change_detail' const eventName = 'data_change_detail'
const count = this.mindMap.event.listenerCount(eventName) const count = this.mindMap.event.listenerCount(eventName)
@ -187,7 +188,10 @@ class Command {
const walkReplace = (root, obj) => { const walkReplace = (root, obj) => {
if (root.children && root.children.length > 0) { if (root.children && root.children.length > 0) {
root.children.forEach((childUid, index) => { root.children.forEach((childUid, index) => {
root.children[index] = obj[childUid] root.children[index] =
typeof childUid === 'string'
? obj[childUid]
: obj[childUid.data.uid]
walkReplace(root.children[index], obj) walkReplace(root.children[index], obj)
}) })
} }
@ -220,6 +224,9 @@ class Command {
}) })
this.mindMap.emit(eventName, res) this.mindMap.emit(eventName, res)
} }
} catch (error) {
this.mindMap.opt.errorHandler && this.mindMap.opt.errorHandler(error)
}
} }
} }