node.js - 在 keystone.js 管理 UI 中显示其他模型(集合)的字段?

标签 node.js mongodb mongoose keystonejs

我有两个模型

/**
 * Page Model
 * =============
 */

var Page = new keystone.List('Page');

Page.add({
    name: { type: String, required: true },
    pid: { type: String, required: true , default:"123" },
    phone: { type: String },
    keyword : {type: Types.Relationship, ref: 'Keyword' , many: true},
    searchvol : {type: Types.Relationship, ref: 'Keyword' , many: true},
    pageType: { type: Types.Select, options: [
        { value: 'message', label: 'Just leaving a message' },
        { value: 'question', label: 'I\'ve got a question' },
        { value: 'other', label: 'Something else...' }
    ] },
    createdAt: { type: Date, default: Date.now }
});

Page.relationship({ path: 'keywords', ref: 'Keyword',    refPath: 'keyword' });
Page.relationship({ path: 'keywords', ref: 'Keyword',    refPath: 'searchvol' });

和关键词模型

/**
 * Keyword Model
 * =============
 */

var Keyword = new keystone.List('Keyword');

Keyword.add({
    //name: { type: String, required: true },
    searchvol: { type: String },
    keywordType: { type: Types.Select, options: [
        { value: 'message', label: 'brand' },
        { value: 'question', label: 'exact match' },
        { value: 'other', label: 'Something else...' }
    ] },
    createdAt: { type: Date, default: Date.now }
});

我想在管理 UI 中包含搜索量,以便我可以使用它进行排序和过滤

但是它似乎只能包含名称字段,如果我删除该字段,它只会显示 id。

解决这个问题的唯一方法是构建一个自定义的 CRUD 界面来处理我的“连接”,或者存在一种方法可以使其与当前设置一起使用。

这是文档的链接,我在其中找到了有关如何执行此操作的一些详细信息。 http://keystonejs.com/docs/database/#relationships

最佳答案

@RaedMarji,Keystone 始终使用 name 字段来显示引用关系。但是,在像您这样的情况下,当您没有 name 字段时,您可以映射现有字段以充当模型的名称。

只需按如下方式更新您的列表定义:

var Keyword = new keystone.List('Keyword', {
    map: { name: 'searchvol' }
});

关于node.js - 在 keystone.js 管理 UI 中显示其他模型(集合)的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28428416/

相关文章:

node.js - Nodejs 工作线程可以用于执行长时间运行的基于文件 I/O 的 JavaScript 代码吗?

mysql - sqlnode.js错误10061

node.js - 多对多关系的正确文件夹结构

node.js - 使用 mongoose 按日期发出排序

java - 使用 Java 在 MongoDB 上迭代聚合

mongodb - Nodejs/ Mongoose : connect to db that's using replica sets

php - 从 MySQL 迁移到 MongoDB - 自增字段

mongodb - 使用对象数组在 MongoDB 中进行聚合

mongodb - Mongo 更新数组的子文档

javascript - 我想从 MongoDB 文档返回特定字段值,但我不断将 [object Promise] 作为返回值