在 joi js .message()

问题描述

我正在尝试获取 joi 中 .message() 中某个键的完整路径,我一直在阅读文档,但我只找到了引用当前键名或使用 label() 的 #key ,但标签似乎不是动态的。这是我当前的代码

const warehouse = Joi.array().items(
    Joi.object().keys({
        name: Joi.string().max(200).required(),capacity: Joi.object().keys({
            totalCoolerCapacity: Joi.string().max(10).pattern(/^(\d{1,6})(\.\d{1,4})?$/).message(`{#key} must not exceed 6 whole numbers and 4 decimal places`).required(),totalNonCoolerCapacity: Joi.string().max(10).pattern(/^(\d{1,4})?$/).required()
        }).required()
    }).required()
).required();

它给出了 totalCoolerCapacity must not exceed 6 whole numbers and 4 decimal places

的验证响应

我期待的是:warehouse[i].capacity.totalCoolerCapacity must not exceed 6 whole numbers and 4 decimal places

我对 node.js 和 joi.js 很陌生,所以我可能错过了一些明显的东西,但感谢任何帮助:)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)