【发布时间】:2017-06-16 05:47:56
【问题描述】:
我正在尝试为 Post 模型实现嵌套类别。
我有什么:
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 }
但效果不佳。
所以,如果有人对如何实现这一目标有任何想法,请分享。 谢谢。
附:不要犹豫,询问任何其他信息。
【问题讨论】:
标签: keystonejs