【发布时间】:2020-02-20 02:24:13
【问题描述】:
我有兴趣为 KeystoneJS 5 编写自定义字段。文档是 here,但我发现它有些不透明(即不完全解释)。有可用的示例代码吗?我查看了 Keystone 存储库中的“演示项目”和“测试项目”,但什么也没看到。
【问题讨论】:
标签: plugins keystonejs
我有兴趣为 KeystoneJS 5 编写自定义字段。文档是 here,但我发现它有些不透明(即不完全解释)。有可用的示例代码吗?我查看了 Keystone 存储库中的“演示项目”和“测试项目”,但什么也没看到。
【问题讨论】:
标签: plugins keystonejs
KeystoneJs 自定义字段的文档记录很差,而且不容易访问。事实上,编写整个自定义字段的整个概念可能是矫枉过正。
这是一位核心团队成员从测试项目中复制的示例。 - https://github.com/MadeByMike/keystone-custom-field/blob/7caf0139c189eadda1884a86073c6945bdd6ff05/index.js#L15
这是你需要做的: 1.你需要为字段创建一个文件夹 2.你可以复制Text field实现开始 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,.
},
}
【讨论】: