繁体   English   中英

需要Joi中的有效字符串,该字符串必须位于其他属性的数组中

[英]Require valid string in Joi which must be in other propertie's array

我想用Joi架构解决以下问题:

有属性locales (arra)和属性default_locale (string),后者必须在locales数组中。

我怎么能做到这一点? 到目前为止,我有以下内容:

Joi.object().keys({
    locales:
        Joi.array()
        .items(
            Joi.string()
            .valid(AllLocales)) // must be any of available locales
        .required(),
    default_locale: // this should be any of the values from locales
        Joi.string()
        .required()
});

我发现我可以简单地使用refhttps://github.com/hapijs/joi/blob/v14.3.1/API.md#refkey-options )。

default_locale: Joi.string().valid(Joi.ref('locales')).required()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM