【问题标题】:Field (Test.title) is required but not initial, and has no default or generated value字段 (Test.title) 是必需的,但不是初始值,并且没有默认值或生成值
【发布时间】:2016-05-26 14:22:12
【问题描述】:

我想知道是否有人知道我为什么会出现这个错误,我的模型

var Test = new keystone.List('Test', {
    autokey: { from: 'title', path: 'key', unique: true }
});

Test.add({
    title: { type: String, required: true },

我所做的只是更改下面帖子示例中的值

var Test = new keystone.List('Test', {
    autokey: { from: 'name', path: 'key', unique: true }
});

Test.add({
    name: { type: String, required: true },

我不明白为什么它适用于名称而不适用于标题

【问题讨论】:

    标签: keystonejs


    【解决方案1】:

    在选项列表中使用映射键

    var Test = new keystone.List('Test', {
        map: { name: 'title' },
        autokey: { from: 'title', path: 'key', unique: true }
    });
    

    参考:http://keystonejs.com/docs/database/#lists-options

    将字段映射到特殊列表路径的对象。每个路径默认 如果添加了具有该键的字段,则添加到其键。可映射路径包括 name - 包含项目名称的字段,用于显示 管理界面

    【讨论】:

      猜你喜欢
      • 2018-06-27
      • 2012-01-23
      • 2012-01-16
      • 2023-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      • 2010-10-18
      相关资源
      最近更新 更多