KeystoneJS 5 自定义字段的示例代码?
Sample code for KeystoneJS 5 custom fields?
我有兴趣为 KeystoneJS 5 编写自定义字段。文档是 here,但我发现它有点不透明(即,没有完全解释)。有可用的示例代码吗?我查看了 Keystone 存储库中的 'demo projects' 和 'test projects',但没有看到任何内容。
KeystoneJs 自定义字段的文档很少且不易访问。事实上,编写整个自定义字段的整个概念可能有点矫枉过正。
这里是一个核心团队成员从测试项目复制的例子。 - https://github.com/MadeByMike/keystone-custom-field/blob/7caf0139c189eadda1884a86073c6945bdd6ff05/index.js#L15
这是您需要做的:
1.您需要为该字段创建一个文件夹
2.您可以复制文本字段实现以开始
3. index.js 文件必须像这样导出特定对象(默认导出)(我为每一行添加了一些注释)
{
type: 'Stars', // name of the implementation
implementation: Stars, // implementation itself
views: { // all views are required you can copy the implementation from Text field)
Controller: Integer.views.Controller, // it is using controller from Integer field type
Field: require.resolve('./views/Field'), // field which goes into edit page or create dialog
Filter: Integer.views.Filter, // this adds filters in the list page
Cell: require.resolve('./views/Cell'), // view for list page where you usually see the text, for Relationship it is rendered as link.
},
adapters: {
mongoose: MongoIntegerInterface, // mongoose adapter specific inplementation
knex: KnexIntegerInterface, // knex adapter specific implementation,.
},
}
- 为每种类型(字段、过滤器、单元格等)创建视图
- 在模式定义中导入字段(默认导入)并像常规字段一样使用它。任何自定义选项都会传递给自定义实现。
我有兴趣为 KeystoneJS 5 编写自定义字段。文档是 here,但我发现它有点不透明(即,没有完全解释)。有可用的示例代码吗?我查看了 Keystone 存储库中的 'demo projects' 和 'test projects',但没有看到任何内容。
KeystoneJs 自定义字段的文档很少且不易访问。事实上,编写整个自定义字段的整个概念可能有点矫枉过正。
这里是一个核心团队成员从测试项目复制的例子。 - https://github.com/MadeByMike/keystone-custom-field/blob/7caf0139c189eadda1884a86073c6945bdd6ff05/index.js#L15
这是您需要做的: 1.您需要为该字段创建一个文件夹 2.您可以复制文本字段实现以开始 3. index.js 文件必须像这样导出特定对象(默认导出)(我为每一行添加了一些注释)
{
type: 'Stars', // name of the implementation
implementation: Stars, // implementation itself
views: { // all views are required you can copy the implementation from Text field)
Controller: Integer.views.Controller, // it is using controller from Integer field type
Field: require.resolve('./views/Field'), // field which goes into edit page or create dialog
Filter: Integer.views.Filter, // this adds filters in the list page
Cell: require.resolve('./views/Cell'), // view for list page where you usually see the text, for Relationship it is rendered as link.
},
adapters: {
mongoose: MongoIntegerInterface, // mongoose adapter specific inplementation
knex: KnexIntegerInterface, // knex adapter specific implementation,.
},
}
- 为每种类型(字段、过滤器、单元格等)创建视图
- 在模式定义中导入字段(默认导入)并像常规字段一样使用它。任何自定义选项都会传递给自定义实现。