我创建了这样一个模型: var keystone = require('keystone'), Types = keystone.Field.Types;var Page = new keystone.List('Page', { autokey: { path: 'slug', from: 'menuTitle', unique: true }, map: { name: 'menuTitle' },});Page.add({ k
var keystone = require('keystone'), Types = keystone.Field.Types; var Page = new keystone.List('Page', { autokey: { path: 'slug', from: 'menuTitle', unique: true }, map: { name: 'menuTitle' }, }); Page.add({ keyword: { type: Types.Key, required: true, initial: false }, slug: { type: Types.Key, required: true, initial: false }, type: { type: Types.Select, options: 'textpage, projects, services, contacts, homepage', default: 'textpage' }, menuTitle: { type: String, required: true, initial: false }, pageTitle: { type: String }, pageContent: { type: Types.Html, wysiwyg: true, height: 400 }, seoTitle: { type: String }, seoKeywords: { type: String }, seoDescription: { type: String }, isActive: { type: Types.Boolean } }); Page.defaultColumns = 'keyword, slug, menuTitle, isActive'; Page.register();
我希望它会生成一个对象列表和一个表单来创建这些对象.
但表格没有字段.
我究竟做错了什么?或者我还应该做些什么才能获得包含所有字段的表单?
基本上,您没有看到任何字段,因为您将初始选项设置为false.初始默认值为false,但“name”字段除外 – 即默认情况下为带有路径名的字段或与您为Keystone提供名称的映射的路径,在您的案例中为menuTitle.
所以通常你的menuTitle字段会显示出来,希望你明确告诉它不要使用initial:false设置.
要显示字段,只需设置要初始化的字段:true,如下所示:
var keystone = require('keystone'), Types = keystone.Field.Types; var Page = new keystone.List('Page', { autokey: { path: 'slug', from: 'menuTitle', unique: true }, map: { name: 'menuTitle' }, }); Page.add({ keyword: { type: Types.Key, required: true, initial: true }, type: { type: Types.Select, options: 'textpage, projects, services, contacts, homepage', default: 'textpage' }, menuTtle: { type: String, required: true, initial: true }, pageTitle: { type: String, initial: true }, pageContent: { type: Types.Html, wysiwyg: true, height: 400 }, seoTitle: { type: String }, seoKeywords: { type: String }, seoDescription: { type: String }, isActive: { type: Types.Boolean } }); Page.defaultColumns = 'keyword, slug, menuTitle, isActive'; Page.register();
另外值得注意的是,您不需要实际添加slug字段;由于您的自动键设置,它会自动添加到架构中.