行字段 (Row Field)

Row Field 仅用于展示目的,且只影响 Admin Panel。通过使用它,你可以将 Fields 水平排列在一起。

展示 Payload 管理面板中的行字段
管理面板中的 Row field 截图

要添加 Row Field,请在 Field Config 中将 type 设置为 row

import type { Field } from 'payload'

export const MyRowField: Field = {
  // ...
  // highlight-start
  type: 'row',
  fields: [
    // ...
  ],
  // highlight-end
}

配置选项

选项描述
fields *嵌套在此行内的字段类型数组
admin特定于管理面板的配置,不包括 descriptionreadOnlyhidden更多详情
custom用于添加自定义数据的扩展点(例如用于插件)

* 星号表示该属性为必填项。

示例

collections/ExampleCollection.ts

import type { CollectionConfig } from 'payload'

export const ExampleCollection: CollectionConfig = {
  slug: 'example-collection',
  fields: [
    {
      type: 'row', // 必需
      fields: [
        // 必需
        {
          name: 'label',
          type: 'text',
          required: true,
          admin: {
            width: '50%',
          },
        },
        {
          name: 'value',
          type: 'text',
          required: true,
          admin: {
            width: '50%',
          },
        },
      ],
    },
  ],
}