Skip to main content

管理关系字段

¥Managing relational fields

从内容类型生成器添加到内容类型的关系类型字段允许与另一个集合类型建立关系。这些字段称为 "关系字段"。

¥Relation-type fields added to a content-type from the Content-type Builder allow establishing a relation with another collection type. These fields are called "relational fields".

关系字段的内容是从它们所属的内容类型的编辑视图写入的(参见 写作内容)。但是,关系字段可以指向其他集合类型的一个或多个条目,这就是为什么在内容管理器中可以管理内容类型的关系字段以选择哪些条目相关。

¥The content of relational fields is written from the edit view of the content-type they belong to (see Writing content). However, relational fields can point to one or several entries of the other collection type, this is why in the Content Manager it is possible to manage a content-type's relational fields to choose which entries are relevant.

Example

在我的 Strapi 管理面板中,我创建了 2 种集合类型:

¥In my Strapi admin panel I have created 2 collection types:

  • 餐厅,每个入口都是一家餐厅

    ¥Restaurant, where each entry is a restaurant

  • 类别,其中每个条目都是一种餐厅类型

    ¥Category, where each entry is a type of restaurant

我想为我的每家餐厅分配一个类别,因此我在两种集合类型之间建立了关系:餐馆可以有一个类别。

¥I want to assign a category to each of my restaurants, therefore I have established a relation between my 2 collection types: restaurants can have one category.

在内容管理器中,从我的餐厅条目的编辑视图中,我可以管理类别关系字段,并选择与我的餐厅相关的类别条目。

¥In the Content Manager, from the edit view of my Restaurant entries, I can manage the Category relational field, and choose which entry of Category is relevant for my restaurant.

Relational fields in the edit viewRelational fields in the edit view

内容类型的关系字段显示在常规字段中。对于每个关系字段,都会显示一个包含所有可用条目标题的下拉列表。它允许选择关系字段应指向哪个条目。你可以根据所建立的关系类型选择一个或多个条目。

¥The relational fields of a content-type are displayed among regular fields. For each relational field is displayed a drop-down list containing all available entry titles. It allows to choose which entry the relational fields should point to. You can either choose one or several entries depending on the type of relation that was established.

提示

默认情况下并未列出所有条目:单击“加载更多”按钮可以显示更多内容。此外,你可以单击任何关系字段下拉列表并键入来搜索特定条目,而不是通过滚动列表来选择条目。

¥Not all entries are listed by default: more can be displayed by clicking on the Load more button. Also, instead of choosing an entry by scrolling the list, you can click any relational field drop-down list and type to search a specific entry.

注意

如果为关系字段所属的内容类型激活了“草稿和发布”功能(请参阅 保存、发布和删除内容),你会注意到下拉列表中条目名称旁边有蓝色或绿色的点。它们指示条目的状态,分别是草稿或已发布的内容。

¥If the Draft & Publish feature (see Saving, publishing and deleting content) is activated for the content-type the relational field belongs to, you will notice blue or green dots next to the entries names in the drop-down list. They indicate the status of the entry, respectively draft or published content.

提醒

如果安装了 国际化插件,则条目列表可能会受到限制,或者因区域设置而异。仅列出可能为关系字段选择的相关条目。

¥If the Internationalization plugin is installed, the list of entries may be limited or differ from one locale to another. Only relevant entries that can possibly be chosen for a relational field will be listed.

管理单选关系字段

¥Managing one-choice relational fields

多对一、一对一和单向关系类型仅允许为每个关系字段选择一个条目。

¥Many-to-one, one-to-one, and one-way types of relation only allow to choose one entry per relational field.

One-choice relational fieldsOne-choice relational fields

要选择唯一相关的关系字段条目:

¥To select the only relevant relational field's entry:

  1. 在内容类型的编辑视图中,单击关系字段的下拉列表。

    ¥In the content-type's edit view, click on the drop-down list of the relational field.

  2. 在条目列表中,选择一项。

    ¥Among the list of entries, choose one.

提示

你可以单击所选条目的名称以重定向到关系字段内容类型的编辑视图。确保先保存页面,以避免丢失最后的修改。

¥You can click on the name of the selected entry to be redirected to the edit view of the relational field's content type. Make sure you save your page first, to avoid losing your last modifications.

要删除下拉列表中的选定条目,请单击删除按钮

¥To remove the entry selected in the drop-down list, click on the delete button .

管理多选关系字段

¥Managing multiple-choice relational fields

多对多、一对多和多方类型的关系允许为每个关系字段选择多个条目。

¥Many-to-many, one-to-many, and many-ways types of relation allow to choose several entries per relational field.

Multiple choices relational fieldsMultiple choices relational fields

要选择相关关系字段的条目:

¥To select the relevant relational field's entries:

  1. 在内容类型的编辑视图中,单击关系字段的下拉列表。

    ¥In the content-type's edit view, click on the drop-down list of the relational field.

  2. 在条目列表中,选择一项。

    ¥Among the list of entries, choose one.

  3. 重复步骤 2,直到选择所有相关条目。

    ¥Repeat step 2 until all relevant entries have been chosen.

提示

所有选定的条目都列在下拉列表的正下方。单击要重定向到关系字段内容类型的编辑视图的条目名称。确保先保存页面,以避免丢失最后的修改。

¥All selected entries are listed right below the drop-down list. Click on the name of an entry to be redirected to the edit view of the relational field's content-type. Make sure you save your page first, to avoid losing your last modifications.

要删除条目,请单击所选条目列表中的十字按钮

¥To remove an entry, click on the cross button in the selected entries list.

可以重新排序多项选择关系字段的条目,通过拖动按钮 表示。要移动条目,请单击并按住它,将其拖动到所需位置,然后释放它。

¥Entries from multiple-choice relational fields can be reordered, indicated by a drag button . To move an entry, click and hold it, drag it to the desired position, then release it.