Skip to main content

不建议使用文档服务 API 更新可重复组件

¥Updating repeatable components with the Document Service API is not recommended

在 Strapi 5 中,由于新文档服务 API 的一些限制,不建议使用 API 更新可重复组件。

¥In Strapi 5, it's not recommended to update repeatable components with the API, due to some limitations of the new Document Service API.

此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。

¥This page is part of the breaking changes database and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

 Is this breaking change affecting plugins?Yes
 Is this breaking change automatically handled by a codemod?No

重大更改描述

¥Breaking change description

在 Strapi v4 中

¥In Strapi v4

你可以使用其 id 更新可重复组件。

¥You could update a repeatable component with its id.

在 Strapi 5 中

¥In Strapi 5

由于引入了 文档服务 API,Strapi 5 使用 documentId,并且由于 起草并发布 功能与新 API 的配合方式,你无法通过其 documentId 更新可重复组件。

¥Strapi 5 uses documentId due to the introduction of the Document Service API, and you can't update a repeatable component by its documentId due to the way the Draft & Publish feature works with the new API.

迁移

¥Migration


注意

¥Notes

在 Strapi 5 中,草稿组件和已发布的组件具有不同的 ID,你可以按如下方式获取数据:

¥In Strapi 5, draft components and published components have different ids, and you could fetch data like follows:

// Request
GET /articles // -> returns published article

// Response
{
documentId …
component: [
{ id: 2, name: 'component-1' },
{ id: 4, name: 'component-2' },
]
}

然后,你可以尝试执行以下操作:

¥You can then try to do the following:

PUT /articles/{documentId} // <== Update draft article
{
documentId …
component: [
{ id: 2, name: 'component-1-updated' }, // <== Update component 1
]
}

但是,这会失败,因为草稿文章的组件 ID 与已发布文章的组件 ID 不同。因此,不建议尝试使用文档服务 API 更新可重复组件。

¥However, this would fail because the component id of the draft article is different from the published one. Therefore, it's not recommended to try to update repeatable components with the Document Service API.