KeystoneJS关系types,按字段值限制可用项目

是否可以通过指定值条件来限制KeystoneJS关系types中的可用显示选项?

基本上,模型有两组数组字段,而不是让pipe理员用户从字段中select任何项目,我想限制只有属于特定集合_id的一部分的项目。

不知道这是否正是您要查找的function,但是您可以在“ Relationship字段中指定一个filter选项作为对象,它将过滤结果,以便只显示匹配的结果。

filter对象中的每个属性都应该是在相关模式中匹配的值,或者可以是与模式中其他path值匹配的dynamic值(用path前缀:)。

例如:

用户架构

 User.add({ state: { type: Types.Select, options: 'enabled, disabled' } }); 

邮政架构

 // Only allow enabled users to be selected as the author Post.add({ author: { type: Types.Relationship, ref: 'User', filter: { state: 'enabled' } } }); 

或者,对于一个dynamic的例子,假设你有一个PostsUsersrole设置。 您只需要匹配与post具有相同role作者。

用户架构

 User.add({ userRole: { type: Types.Select, options: 'frontEnd, backEnd' } }); 

邮政架构

 Post.add({ postRole: { type: Types.Select, options: 'frontEnd, backEnd' }, // only allow users with the same role value as the post to be selected author: { type: Types.Relationship, ref: 'User', filter: { userRole: ':postRole' } } }); 

请注意,这不是实际上作为后端validation实施,它只是在pipe理界面中实现。 所以这更多的是一个可用性增强而不是限制。

为了扩大杰德的答案,我认为正确的属性(至less在最新版本的KeystoneJS 0.2.22)是“filter”,而不是“filter”。 “filter”不适合我。