看起来您可以使用any.custom 方法并向您传递自定义验证逻辑。基于该文档,我们首先需要创建一个函数来验证接受两个参数的字符串数组,即“值”和“助手”对象。const contentsLength = (value, helpers) => { // do a map reduce to calculate the total length of strings in the array const len = value.map((v) => v.length).reduce((acc, curr) => acc + curr, 0); // make sure that then length doesn't exceed 20, if it does return an error using // the message method on the helpers object if (len > 200) { return helpers.message( "the contents of the array must not exceed 200 characters" ); } // otherwise return the array since it's valid return value;};现在将它添加到您的items架构中const items = Joi.array().items(item).max(20).custom(contentsLength);