我想在对象的Yup数组中设置number属性的验证,这样
每个对象的
。
const ParamValidator = Yup.object()
.shape({
params: Yup.array()
.of(
Yup.object()
.shape({
name: Yup.string.max(30).required(),
weight: Yup.number().min(0).max(100).required(),
})
.required(),
)
.required()
不管我想出了什么,我都能说出我的观点。以最小和最大为单个对象的重量,但不能做到(2.)我怎么才能把所有物体的重量之和算出来。只使用Yup验证
发布于 2021-11-09 13:11:43
const ParamValidator = Yup.object()
.shape({
params: Yup.array()
.of(
Yup.object()
.shape({
name: Yup.string.max(30).required(),
weight: Yup.number().min(0).max(100).required(),
})
.required(),
)
.required()
.test('params',
'sum of weights of all objects of params should be <= 100',
(values: any[]) => values.reduce((acc, curr) => acc + curr.weight, 0) <= 100,)https://stackoverflow.com/questions/69894597
复制相似问题