繁体   English   中英

如何在对象数组中查找和比较单独的对象值

[英]how to find and compare separate objects value in array of objects

我正在尝试制作 React 注册表单。

我的任务是为表单创建输入字段并通过正则表达式检查它们的值,并将密码值和重复密码与 email 进行比较。

没关系,但检查密码和 r.password 的值很难

const fieldsValidation = () => {
  const newState = [...fieldsState];
  for (let [index, element] of newState.entries()) {

    if (element.value.length < element.valueLength) {
      return changeFields(() => {
        newState[index].error = true;
        return newState;
      });
    }
  };
  return registerUser();
};

这是我试图与我的反应项目集成的配置

export const textFieldConfig = [{
    id: 'email',
    type: 'email',
    label: 'email',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'email must include 8 char and @.',
    valueLength: 8
  },
  {
    id: 'password',
    type: 'password',
    label: 'password',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'password must be min 6',
    valueLength: 6
  },
  {
    id: 'repeatPassword',
    type: 'password',
    label: 'repeat-password',
    value: '',
    variant: 'outlined',
    size: 'small',
    error: false,
    helperText: 'please include same password value',
    valueLength: 6
  }
];

我想如果你的 Object 没有改变这会做

if(textFieldConfig[1].value == textFieldConfig[2].value){
....
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM