【问题标题】:Show fields from other models (collections) in keystone.js admin UI?在 keystone.js 管理 UI 中显示来自其他模型(集合)的字段?
【发布时间】:2015-04-10 07:02:09
【问题描述】:

我有两个模型

/**
 * 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

【问题讨论】:

    标签: node.js mongodb mongoose keystonejs


    【解决方案1】:

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

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

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

    【讨论】:

    • 我理解这一点,但是如果我想显示来自其他集合的多个值,例如名称、搜索文本和类型,该怎么办。都属于同一个id。
    • 抱歉,您的问题并不清楚。我只知道您想要“在管理 UI 中包含搜索量”。不幸的是,目前这是不可能的。我相信目前还有另一个相关问题悬而未决。
    • 是的,我理解您的困惑,而且似乎没有执行此操作的实现。在我看来这很奇怪。但是我认为它可以以与名称相同的方式完成。也许有人可以调查一下。我会尝试自己看一下,也许我可以解决。
    猜你喜欢
    • 2016-06-26
    • 2014-12-07
    • 2016-02-20
    • 1970-01-01
    • 2012-05-28
    • 2021-10-18
    • 2020-03-18
    • 2017-04-30
    • 2014-12-01
    相关资源
    最近更新 更多