2017-02-26 3 views
1

게시 모델에 중첩 된 범주를 구현하려고합니다.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(); 

:

답변

0

나는 그들이 하위 범주를 만들 때 사용자가 하위 범주 상위 범주를 할당 할 수있는 새로운 모델 'PostSubCategory'를 작성하여 중첩 된 카테고리를 생성 난 단지 선택된 상위 카테고리의 자녀 하위 범주에서 선택 해당 필드에 필터를 하위 범주를 선택하는 필드를 추가 :

subcategory: { 
    type: Types.Relationship, 
    ref: 'PostSubCategory', 
    many: false, 
    filters: { parentCategory: ':categories' } 
} 

나는이 깊은 중첩을 위해 일하는 것이 얼마나 잘 모르겠어요, 그리고 나는 t에 문제가있다. 그는 게시물 관리자의 ui를 편집합니다. 게시물의 상위 카테고리를 변경해도 저장하고 새로 고침 할 때까지 선택할 수있는 하위 카테고리가 업데이트되지 않습니다. 그러나 그것은 부모/자식 범주를 얻는 데 충분할 정도로 나를 필요로합니다.