javascript - 要求 Joi 中的有效字符串必须在其他属性的数组中
问题描述
我想用 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()
});
解决方案
我发现我可以简单地使用ref
(https://github.com/hapijs/joi/blob/v14.3.1/API.md#refkey-options)。
default_locale: Joi.string().valid(Joi.ref('locales')).required()
推荐阅读
- android - couchbase syncgateway 是否支持使用 access_token 而不是 id_token 登录?
- mongodb - 如何获取不在集合中的元素?
- python - 在Odoo中,在编写控制器时,http和https有什么区别?有一个错误
- mysql - SELECT 语句优化 MySQL
- php - 如何根据从上一页收到的 ID 生成页面(php/sql)
- python - Django admin 自定义降序和升序字段
- javascript - moment.js,根据 locale dow 列出天数
- api - 将 SendInBlue 连接到 Magento 1.9
- database - 以编程方式创建租户数据库
- c# - 将事件序列化为 JSON