【发布时间】:2017-03-17 17:31:04
【问题描述】:
我正在尝试将 Keystone 制作成 CMS。所以,我需要 Article、Category、ImagePage、AttachmentPage 等模型。我提到的每个模型都有一个公共字段的子集,例如:标题、内容、元:{标题、描述、关键字}等等。
在 Keystone 中,模型的构造如下:
Article.add(fieldsCollectionObject)
所以我在外部文件中定义了公共字段:
var T = require('keystone').Field.Types;
module.exports = {
title: { type: T.Text, required: true },
content: { type: T.Html, wysiwyg: true, height: 400 },
meta: {
title: { type: T.Text },
desc: { type: T.Textarea, height: 50 },
keywords: { type: T.Text },
},
publishedDate: { type: T.Date, index: true, dependsOn: { state: 'published' } },
state: { type: T.Select, options: 'draft, published, archived', default: 'draft', index: true },
};
并且在模型文件中需要它:
const _ = require('lodash');
const pageDef = require('./common/Page.js');
const keystone = require('keystone');
const T = keystone.Field.Types;
<...>
Article.add(_.defaultsDeep({
brief: { type: T.Html, wysiwyg: true, height: 150 },
category: { type: T.Relationship, ref: 'Category', many: false, collapse: true },
tags: { type: T.Relationship, ref: 'Tag', many: true },
}, defs.authored, pageDef));
现在,问题在于管理 UI 中的字段顺序 - 不出所料,brief、category 和 tags 排在来自 pageDef 的字段之前。有没有办法强加我想要的命令?喜欢title、brief、content、<the rest>?
【问题讨论】:
标签: node.js lodash keystonejs