【问题标题】:Keystonejs how to access models in a templateKeystonejs如何访问模板中的模型
【发布时间】:2014-12-29 20:59:19
【问题描述】:

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

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();

【问题讨论】:

    标签: node.js express pug keystonejs


    【解决方案1】:
    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');
    
    };
    

    【讨论】:

      猜你喜欢
      • 2015-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多