【问题标题】:Sample code for KeystoneJS 5 custom fields?KeystoneJS 5 自定义字段的示例代码?
【发布时间】:2020-02-20 02:24:13
【问题描述】:

我有兴趣为 KeystoneJS 5 编写自定义字段。文档是 here,但我发现它有些不透明(即不完全解释)。有可用的示例代码吗?我查看了 Keystone 存储库中的“演示项目”和“测试项目”,但什么也没看到。

【问题讨论】:

    标签: plugins keystonejs


    【解决方案1】:

    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,.
      },
    }
    
    1. 为每种类型(字段、过滤器、单元格等)创建视图
    2. 在架构定义中导入字段(默认导入)并像常规字段一样使用它。任何自定义选项都会传递给自定义实现。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 2015-03-15
    • 2020-09-19
    • 2021-08-18
    • 2018-05-20
    • 1970-01-01
    • 2014-09-06
    相关资源
    最近更新 更多