2016-11-24 28 views
0

我想为具有以下格式文档的SimpleSchemaSimpleSchema可以使用自定义键和特定的值来表示“对象”吗?

{ 
    ..., 
    permissions: { 
    foo: {allow: ["user1", "user2"]}, 
    bar: {allow: ["admin"]}, 
    } 
} 

如果foobar是众所周知的模式字符串,我只是这样做:

const PermissionsSchema = new SimpleSchema({ 
    allow: {type: [String]}, 
}); 

new SimpleSchema({ 
    ..., 
    'permissions.foo': { 
    type: PermissionSchema, 
    }, 
    'permissions.bar': { 
    type: PermissionSchema, 
    }, 
}) 

然而在这种情况下,可以有任意的字符串键,不仅仅是foobar。这些值必须始终匹配PermissionsSchema。有没有办法表达这一点?

回答

0

Custom validators来救援!

虽然出来的错误消息是垃圾。改进或更好的策略仍然受欢迎。

相关问题