reactjs - 从 MongoDB 填充 Material-UI DataGrid 失败,找不到唯一 ID

标签 reactjs mongodb material-ui

错误:Material-UI:数据网格组件要求所有行都具有唯一的 id 属性。
当我调用表格时,我在行 Prop 中没有提供一行是我所看到的。
这是我定义表的方式。

const columns = [
  { field: "_id", hide: true },
  { field: "user", headerName: "User", width: 70 },
  { field: "fromaddress", headerName: "Sender", width: 70 },
  { field: "dkimSpfChk", headerName: "DKIM/SPF", width: 70 },
  { field: "replySenderMismatch", headerName: "Reply MisMatch", width: 70 },
  { field: "riskywordchk", headerName: "Risky Word", width: 70 },
  { field: "domainagechk", headerName: "Sender Domain Age", width: 70 },
  { field: "attachmentChk", headerName: "Attachments", width: 70 },
  { field: "riskyLinkAge", headerName: "Body Link Age", width: 70 },
  { field: "riskyLinkTypo", headerName: "Link Typosquatting", width: 70 },
  {
    field: "senderTypoSquatting",
    headerName: "Sender TypoSquatting",
    width: 70,
  }
];
我从我的 api 中获取数据,然后在行中填充
 useEffect(() => {
    var apiurl = "http://localhost:5000/adminportal/highRiskEmails";
    axios
      .get(apiurl)
      .then((response) => response.data)
      .then((data) => {
        setIsLoaded(true);
        setRowData(data);
      });
  }, []);
这是数据网格
return (
  <div style={{ height: 400, width: "100%" }}>
    <DataGrid
      rows={rowData}
      columns={columns}
      id="_id"
      pageSize={15}
      checkboxSelection
    />
  </div>
);
我知道 _id 字段在 Mongo 中是独一无二的,所以想知道我错过了什么。我是否必须定义 id 字段不是 id 而是 _id?
谢谢

最佳答案

我也很难过,原来你可以制作虚拟ID
https://mongoosejs.com/docs/tutorials/virtuals.html

关于reactjs - 从 MongoDB 填充 Material-UI DataGrid 失败,找不到唯一 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64375119/

相关文章:

javascript - 格式 xx-xx 的正则表达式(不包含字母)

javascript - Draft js 保存和渲染或显示内容

javascript - 无法从数据库获取数据

reactjs - 是否可以在 Material ui 芯片组件上添加工具提示?

javascript - <FormControl/> 不接受变体 Prop

javascript - Reactjs 中功能组件的 Redux(网络)

reactjs - React 返回 200 表示未找到页面?

mongodb - 为什么我的更新 $set 代码会删除我的整个文档?

node.js - Nodejs express API 一个 sequelize(db) 实例到所有模型

reactjs - MUI v5 : Failed prop type: The prop `direction` of `Grid` can only be used together with the `container` prop