如何将新字段添加到 KeystoneJS 中的列表
How to add new fields to a list in KeystoneJS
我想通过向 Post 架构添加一个布尔值 "frontPage" 字段来扩展 KeystoneJS 中的博客,我想用它来在主页上显示选定的帖子。
我想到了我放在更新文件夹中的这段代码:
var keystone = require('keystone');
var async = require('async');
exports = module.exports = function (done) {
let post = keystone.list('Post');
post.add({
frontPage: Boolean
});
done();
};
它似乎有效,但当我重新启动服务器时,更改并没有持续存在。所有文档都描述了创建新列表的过程,但 none 说明了如何修改现有列表。还尝试在末尾添加 post.register()
但没有成功。
是否有保留新模式的功能,或者我应该在 Keystone 之外为此编写一个 shell 脚本?
谢谢
It seems to work, but the change does not persist when I restart the server.
application updates
folder 中的脚本用于数据导入或迁移,并且有意仅对给定部署应用一次。
All docs describe the process of creating new Lists, but none tells how to modify an existing one.
要添加、删除或更改模型中的字段,您应该修改 Keystone 项目中的文件(例如:models/Post.js
),然后重新启动应用程序以使更改生效。
通常不需要创建相应的 update
脚本,除非您想包含相关的数据更改(例如,为现有文档设置值)。
我想通过向 Post 架构添加一个布尔值 "frontPage" 字段来扩展 KeystoneJS 中的博客,我想用它来在主页上显示选定的帖子。
我想到了我放在更新文件夹中的这段代码:
var keystone = require('keystone');
var async = require('async');
exports = module.exports = function (done) {
let post = keystone.list('Post');
post.add({
frontPage: Boolean
});
done();
};
它似乎有效,但当我重新启动服务器时,更改并没有持续存在。所有文档都描述了创建新列表的过程,但 none 说明了如何修改现有列表。还尝试在末尾添加 post.register()
但没有成功。
是否有保留新模式的功能,或者我应该在 Keystone 之外为此编写一个 shell 脚本?
谢谢
It seems to work, but the change does not persist when I restart the server.
application updates
folder 中的脚本用于数据导入或迁移,并且有意仅对给定部署应用一次。
All docs describe the process of creating new Lists, but none tells how to modify an existing one.
要添加、删除或更改模型中的字段,您应该修改 Keystone 项目中的文件(例如:models/Post.js
),然后重新启动应用程序以使更改生效。
通常不需要创建相应的 update
脚本,除非您想包含相关的数据更改(例如,为现有文档设置值)。