【发布时间】:2021-03-19 18:54:56
【问题描述】:
我试图循环一个数组并比较所有对象值是否不为空,如果所有输入(对象值)都不为空,则转到下一步,否则显示错误。
单击“Agregar”按钮应该循环数组并查看输入是否为空'
代码如下:
const onAdd = () => {
var match = false;
for (let index = 0; index <= entities.length; index++) {
entities.map((value) => {
if (
value.entityName?.trim() == "" ||
value.personInCharge?.trim() == "" ||
value.emailPersonInCharge?.trim() == ""
) {
match = true;
} else {
match = false;
}
});
}
if (match) {
toast.error(
"Completa todos los campos o marque la casilla de `Solo una compañia` "
);
} else {
entities.push(defaultFields);
const newData = entities.map((d, index) => {
return d;
});
setData({ entities: newData });
setData({ ...dataNewChannel, entities: newData });
}
}
【问题讨论】:
-
问题是什么? -> How do I ask a good question?
标签: javascript html reactjs