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 中

你可以使用它的 id 来更新可重复的组件。

🌐 You could update a repeatable component with its id.

在 Strapi 5 中

Strapi 5 使用 documentId 是因为引入了 Document Service API,并且由于新的 API 与 Draft & Publish 功能的工作方式,你无法通过 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 与已发布文章的不同。因此,不建议尝试使用文档服务 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.