2
我是node.js以及keystone的新手。 我想創建一個稱爲頁面的新模型,它與從keystone默認的帖子相同。如何從管理部分在keystone.js中創建頁面
我創建新模型代碼
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
這說明我什麼。即使沒有顯示任何錯誤。 任何幫助將不勝感激。