fix: 以节点id作为key,修复拖拽、增删时组件频繁卸载的问题

This commit is contained in:
wuyue.xht 2021-06-10 14:36:19 +08:00 committed by 力皓
parent 8fd8e7d45a
commit c8e2f9d8ef

View File

@ -372,7 +372,7 @@ export default function baseRenererFactory() {
} }
if (Array.isArray(schema)) { if (Array.isArray(schema)) {
if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo); if (schema.length === 1) return this.__createVirtualDom(schema[0], self, parentInfo);
return schema.map((item, idy) => this.__createVirtualDom(item, self, parentInfo, item?.__ctx?.lceKey ? '' : idy)); return schema.map((item, idy) => this.__createVirtualDom(item, self, parentInfo, item?.__ctx?.lceKey ? '' : String(idy)));
} }
// FIXME // FIXME
const _children = this.getSchemaChildren(schema); const _children = this.getSchemaChildren(schema);
@ -484,6 +484,7 @@ export default function baseRenererFactory() {
} }
props.key = props.key || `${schema.__ctx.lceKey}_${schema.__ctx.idx || 0}_${idx !== undefined ? idx : ''}`; props.key = props.key || `${schema.__ctx.lceKey}_${schema.__ctx.idx || 0}_${idx !== undefined ? idx : ''}`;
} else if (typeof idx === 'number' && !props.key) { } else if (typeof idx === 'number' && !props.key) {
// 仅当循环场景走这里
props.key = idx; props.key = idx;
} }