楚河之界
2022-06-06 11:09
采纳率: 92.6%
浏览 43

react数组的数据处理


let fileMessage = [
    {
      code: 'file-invalid-type',
      message: 'Select the correct file type',
    },
    {
      code: 'file-too-large',
      message: 'Total File Size is limited to maximum 25MB',
    },
  ];

let fileRejections = [
    {
      errors: [
        { code: 'file-invalid-type', message: 'File type must be one of image/*' },
        { code: 'file-too-large', message: 'File is larger than 26214400 bytes' }  // 有可能是这行数据
      ],
    },
  ];

const fileRejectionItems = fileRejections.map(({ file, errors }) => (
    <div key={file.path}>
      <>
        {errors.map((e) => (
          <ErrorMsg
            key={e.code}
            className={classes.errorMsg}
            type='error'
            label={fileMessage.find((i) => (i.code === e.code ? i : e.message)).message}
          />
        ))}
      </>
    </div>
  ));

希望根据code相等,return fileMessage 里对应的message,但是始终return这个message: 'Select the correct file type'

3条回答 默认 最新

相关推荐 更多相似问题