我创建了一个新模型,它显示在管理用户界面上,但我如何从模板中访问它?

var keystone = require('keystone'),
    Types = keystone.Field.Types;


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


Content.add({
    title: { type: String, required: false },
    state: { type: Types.Select, options: 'draft, published, archived', default: 'archived'},
    author: { type: Types.Relationship, ref: 'User', index: true },
    content: {
        brief: { type: Types.Html, wysiwyg: true, height: 100  }
    }
});

Content.defaultColumns = 'title';
Content.register();

最佳答案

var keystone = require('keystone');

exports = module.exports = function(req, res) {

var view = new keystone.View(req, res),
    locals = res.locals;

// locals.section is used to set the currently selected
// item in the header navigation.
locals.section = 'home';

// Render the view
view.query('Rekrys', keystone.list('Rekrys').model.find());
view.render('rekry');

};

关于node.js - Keystonejs如何访问模板中的模型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26710265/

10-10 13:10