错误: 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 (
);我知道_id字段在Mongo中是唯一的,所以我想知道我遗漏了什么。我是否必须定义id字段不是id,而是_身份证?
谢谢
发布于 2021-02-26 05:10:49
您现在可以使用getRowId属性,该属性接受指定应将每行上的哪个属性视为id的函数。
在OP的情况下,您可以这样做:getRowId={(row) => row._id}
发布于 2021-02-19 23:40:23
我只是把这个选项{虚拟: true }在我的方案中:
const opts = { toJSON: { virtuals: true } };
const schema = new mongoose.Schema({
lastName: String,
firstName: String,
nickname: String,
}, opts);因此,当我尝试查询时,该字段"id“已添加。类似于:{“_id":"602fc7aba323ec87f00f9c76","lastName":“坦格利安”,"firstName":“丹妮莉丝”,“昵称”:"",“__v":0,"id":"602fc7aba323ec87f00f9c76“}
发布于 2020-12-01 00:31:09
我也很难做到这一点,原来你可以做虚拟身份证https://mongoosejs.com/docs/tutorials/virtuals.html
https://stackoverflow.com/questions/64375119
复制相似问题