gpt4 book ai didi

node.js - Keystonejs 如何访问模板中的模型

转载 作者:搜寻专家 更新时间:2023-11-01 00:01:51 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com