我是 node.js 和 keystone 的新手。我想创建一个名为 pages 的新模型,它与 keystone 默认的 post 相同。
我创建的新模型代码为
var pages = new keystone.List('pages', {
map: { name: 'title' },
autokey: { path: 'slug', from: 'title', unique: true }
});
pages.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'published', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
image: { type: Types.LocalFile, dest: 'public/uploads'},
content: {
brief: { type: Types.Html, wysiwyg: true, height: 150 },
extended: { type: Types.Html, wysiwyg: true, height: 400 }
},
});
pages.schema.virtual('content.full').get(function() {
return this.content.extended || this.content.brief;
});
pages.defaultColumns = 'title, state|20%, author|20%, publishedDate|20%';
pages.register();
然后我为页面创建了一条路线
exports = module.exports = function(req, res) {
var view = new keystone.View(req, res),
locals = res.locals;
// Init locals
locals.section = 'pages';
locals.data = {
pages: []
};
// Load the pages
view.on('init', function(next) {
var q = keystone.list('pages').paginate({
page: req.query.page || 1,
perPage: 10,
maxPages: 10
})
.where('state', 'published')
.sort('-publishedDate');
q.exec(function(err, results) {
locals.data.pages = results;
next(err);
});
});
// Render the view
view.render('pages');
};
还创建了中间件
{ label: 'pages', key: 'pages', href: '/pages' }
这就是我为创建模型所做的一切......让我知道我错过了什么。当我通过以下代码从 pages.jade 文件中调用它时:
data.pages.title
这告诉我什么。即使没有显示任何错误。任何帮助将不胜感激。