2015-02-10 76 views
2

我有兩個型號在keystone.js admin UI中顯示來自其他模型(集合)的字段?

/** 
* 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 } 
}); 

我想包括在管理界面中的搜索量,這樣我可以排序使用和過濾

但它似乎只能包含名稱字段,如果我刪除該字段,它只會顯示該ID。

因此,解決這個問題的唯一方法是構建一個自定義crud界面來處理我的「聯接」,或者存在一種方法使其與當前設置一起工作。

這裏是我找到一些關於如何做到這一點的文檔的鏈接。 http://keystonejs.com/docs/database/#relationships

回答

3

@RaedMarji,Keystone總是使用name字段來顯示引用關係。但是,在您的情況下,如果您沒有name字段,則可以將現有字段映射爲模型名稱。

只需更新列表定義如下:

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

我明白這一點,但怎麼樣,如果我要顯示來自其他集合多個值,如姓名,搜尋和類型。這些都屬於同一個ID。 – RaedMarji 2015-02-11 11:03:32

+0

對不起,你的問題並不清楚。所有我明​​白你想要什麼「將搜索量包含在管理界面中」。不幸的是,目前這是不可能的。我相信目前還有另一個相關問題。 – JME 2015-02-11 11:14:22

+0

是的,我明白你的困惑,似乎沒有執行此操作的實現。這在我看來很奇怪。不過我認爲可以按照名稱完成的方式完成。也許有人可以看看它。我會嘗試看看自己,也許我可以解決它。 – RaedMarji 2015-02-12 10:25:57

相關問題