diff --git a/packages/amis-editor/src/plugin/Cards.tsx b/packages/amis-editor/src/plugin/Cards.tsx index 94c7362ed..aa30b20ba 100644 --- a/packages/amis-editor/src/plugin/Cards.tsx +++ b/packages/amis-editor/src/plugin/Cards.tsx @@ -545,18 +545,24 @@ export class CardsPlugin extends BasePlugin { node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/); let field = node.schema.name || match?.[1]; const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`); - const schema = scope?.parent?.getSchemaByPath(field); - if (isObject(schema?.items)) { - dataSchema = { - ...dataSchema, - ...(schema!.items as any) - }; - // 列表添加序号方便处理 - set(dataSchema, 'properties.index', { - type: 'number', - title: '索引' - }); + if (scope) { + const origin = this.manager.dataSchema.current; + this.manager.dataSchema.switchTo(scope.parent!); + const schema = this.manager.dataSchema.getSchemaByPath(field); + this.manager.dataSchema.switchTo(origin); + if (isObject(schema?.items)) { + dataSchema = { + ...dataSchema, + ...(schema!.items as any) + }; + + // 列表添加序号方便处理 + set(dataSchema, 'properties.index', { + type: 'number', + title: '索引' + }); + } } return dataSchema; diff --git a/packages/amis-editor/src/plugin/Each.tsx b/packages/amis-editor/src/plugin/Each.tsx index 9e4e2f244..181b5658e 100644 --- a/packages/amis-editor/src/plugin/Each.tsx +++ b/packages/amis-editor/src/plugin/Each.tsx @@ -397,19 +397,24 @@ export class EachPlugin extends BasePlugin { node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/); let field = node.schema.name || match?.[1]; const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`); - const schema = scope?.parent?.getSchemaByPath(field); - if (isObject(schema?.items)) { - dataSchema = { - ...dataSchema, - ...(schema!.items as any) - }; + if (scope) { + const origin = this.manager.dataSchema.current; + this.manager.dataSchema.switchTo(scope.parent!); + const schema = this.manager.dataSchema.getSchemaByPath(field); + this.manager.dataSchema.switchTo(origin); + if (isObject(schema?.items)) { + dataSchema = { + ...dataSchema, + ...(schema!.items as any) + }; - // 循环添加索引方便渲染序号 - set(dataSchema, 'properties.index', { - type: 'number', - title: '索引' - }); + // 列表添加序号方便处理 + set(dataSchema, 'properties.index', { + type: 'number', + title: '索引' + }); + } } return dataSchema; diff --git a/packages/amis-editor/src/plugin/List.tsx b/packages/amis-editor/src/plugin/List.tsx index e7ee523b1..0692aa611 100644 --- a/packages/amis-editor/src/plugin/List.tsx +++ b/packages/amis-editor/src/plugin/List.tsx @@ -353,19 +353,24 @@ export class ListPlugin extends BasePlugin { node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/); let field = node.schema.name || match?.[1]; const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`); - const schema = scope?.parent?.getSchemaByPath(field); - if (isObject(schema?.items)) { - dataSchema = { - ...dataSchema, - ...(schema!.items as any) - }; + if (scope) { + const origin = this.manager.dataSchema.current; + this.manager.dataSchema.switchTo(scope.parent!); + const schema = this.manager.dataSchema.getSchemaByPath(field); + this.manager.dataSchema.switchTo(origin); + if (isObject(schema?.items)) { + dataSchema = { + ...dataSchema, + ...(schema!.items as any) + }; - // 循环添加序号方便处理 - set(dataSchema, 'properties.index', { - type: 'number', - title: '序号' - }); + // 列表添加序号方便处理 + set(dataSchema, 'properties.index', { + type: 'number', + title: '索引' + }); + } } return dataSchema; diff --git a/packages/amis-editor/src/plugin/List2.tsx b/packages/amis-editor/src/plugin/List2.tsx index 4ccc4af6f..324153767 100644 --- a/packages/amis-editor/src/plugin/List2.tsx +++ b/packages/amis-editor/src/plugin/List2.tsx @@ -421,18 +421,24 @@ export class List2Plugin extends BasePlugin { node.schema.source && String(node.schema.source).match(/{([\w-_]+)}/); let field = node.schema.name || match?.[1]; const scope = this.manager.dataSchema.getScope(`${node.id}-${node.type}`); - const schema = scope?.parent?.getSchemaByPath(field); - if (isObject(schema?.items)) { - dataSchema = { - ...dataSchema, - ...(schema!.items as any) - }; - // 列表添加序号方便处理 - set(dataSchema, 'properties.index', { - type: 'number', - title: '索引' - }); + if (scope) { + const origin = this.manager.dataSchema.current; + this.manager.dataSchema.switchTo(scope.parent!); + const schema = this.manager.dataSchema.getSchemaByPath(field); + this.manager.dataSchema.switchTo(origin); + if (isObject(schema?.items)) { + dataSchema = { + ...dataSchema, + ...(schema!.items as any) + }; + + // 列表添加序号方便处理 + set(dataSchema, 'properties.index', { + type: 'number', + title: '索引' + }); + } } return dataSchema;