自定义字段
¥Custom Fields
Page summary:
Custom Fields extend Strapi with new field types that behave like native fields in the Content‑type Builder and Content Manager. Instructions in this documentation cover building or installing fields via plugins and registering them programmatically.
自定义字段通过向内容类型和组件添加新类型的字段来扩展 Strapi 的功能。通过插件创建或添加到 Strapi 后,自定义字段可以像内置字段一样在内容类型生成器和内容管理器中使用。
¥Custom fields extend Strapi’s capabilities by adding new types of fields to content-types and components. Once created or added to Strapi via plugins, custom fields can be used in the Content-Type Builder and Content Manager just like built-in fields.
配置
¥Configuration
可以在 市场 上找到现成的自定义字段。安装这些插件后,无需其他配置,即可开始使用(参见 usage)。
¥Ready-made custom fields can be found on the Marketplace. Once installed these, no other configuration is required, and you can start using them (see usage).
你也可以开发自己的自定义字段。
¥You can also develop your own custom field.
开发你自己的自定义字段
¥Developing your own custom field
虽然添加自定义字段的推荐方法是通过创建插件,但特定于应用的自定义字段也可以在 src/index 和 src/admin/app 文件中找到的全局 register function 中注册。
¥Though the recommended way to add a custom field is through creating a plugin, app-specific custom fields can also be registered within the global register function found in src/index and src/admin/app files.
-
自定义字段只能使用插件在 Marketplace 上共享和分发。
¥Custom fields can only be shared and distributed on the Marketplace using plugins.
-
自定义字段无法向 Strapi 添加新数据类型,必须使用 模型的属性 文档中描述的现有内置 Strapi 数据类型。
¥Custom fields cannot add new data types to Strapi and must use existing, built-in Strapi data types described in the models' attributes documentation.
-
你也无法修改现有的数据类型。
¥You also cannot modify an existing data type.
-
Strapi 特有的特殊数据类型(例如关系、媒体、组件或动态区域数据类型)不能在自定义字段中使用。
¥Special data types unique to Strapi, such as relation, media, component, or dynamic zone data types, cannot be used in custom fields.
通过插件注册自定义字段需要创建并启用插件(参见 插件开发)。
¥Registering a custom field through a plugin requires creating and enabling a plugin (see Plugins development).
自定义字段插件包括服务器和管理面板部分。自定义字段必须先在两个部分中注册,然后才能在 Strapi 的管理面板中使用。
¥Custom field plugins include both a server and admin panel part. The custom field must be registered in both parts before it is usable in Strapi's admin panel.