게시 모델에 중첩 된 범주를 구현하려고합니다.Keystone.js 중첩 범주
내가 무엇을 가지고 :
Post.add({
title: { type: String, required: true },
state: { type: Types.Select, options: 'draft, published, archived', default: 'draft', index: true },
author: { type: Types.Relationship, ref: 'User', index: true },
publishedDate: { type: Types.Date, index: true, dependsOn: { state: 'published' } },
content: {
extended: { type: Types.Html, wysiwyg: true, height: 300 },
},
categories: { type: Types.Relationship, ref: 'PostCategory', index: true }
});
그리고 카테고리
PostCategory.add({
name: { type: String, required: true },
subCategories: { type: Types.TextArray }
});
가 지금은 각 카테고리에 하위 카테고리 목록을 추가 할 수 있습니다. 내가 할 수없는 것은 게시물을 만드는 동안 하위 범주를 표시하는 것입니다. 또한 카테고리를 변경하면 선택한 카테고리와 관련된 하위 카테고리를로드해야합니다.
내 계획은 시계 기능으로이를 달성하는 것이지만 저장시에만 작동하는 것처럼 보입니다.
나는 관계로 하위 범주를 추가하는 것이었다에 대해 생각했다 또 다른 것은, 심판 참조 :
categories: { type: Types.Relationship, ref: 'PostCategory.subCategories', index: true }
을하지만 그것은뿐만 아니라 작동하지 않습니다.
아무도 아이디어를 얻지 못했다면 공유하십시오. 감사합니다. .
P. 추가 정보를 요구하는 것을 망설이지 말라. 내 Post.js에서 다음
var keystone = require('keystone');
var Types = keystone.Field.Types;
/**
* PostSubCategory Model
* ==================
*/
var PostSubCategory = new keystone.List('PostSubCategory', {
autokey: { from: 'name', path: 'key', unique: true },
});
PostSubCategory.add({
name: {
type: String,
required: true
},
parentCategory: {
type: Types.Relationship,
ref: 'PostCategory',
required: true,
initial: true
}
});
PostSubCategory.relationship({ ref: 'Post', path: 'subcategories' });
PostSubCategory.register();
: