[英]JS says an object is undefined even though it shows with console.log
As the title states, my JS says an object is undefined even though if I console.log the parent it shows.正如标题所述,我的 JS 说 object 是未定义的,即使我 console.log 它显示的父级也是如此。 I'm using prisma, but all that does is return a list of the objects containing
{id, title, user:{id, name}}
.我正在使用 prisma,但所做的只是返回包含
{id, title, user:{id, name}}
的对象列表。 Code:代码:
const userProjects = await prisma.projectMembers.findMany({
where: {
userId: token._id
},
select: {
project: {
select: {
id: true,
title: true,
user: {
select: {
id: true,
name: true,
},
},
},
},
},
});
userProjects.map(project => {
console.log(project)
console.log(project.user)
return {
id: project.id,
title: project.title,
user: project.user.id,
}
})
Output: Output:
As you can see in the screenshot, there's a nested project
property, and the user
property is inside that.正如您在屏幕截图中看到的那样,有一个嵌套的
project
属性, user
属性在其中。 So project.user
should be project.project.user
.所以
project.user
应该是project.project.user
。
userProjects.map(project => {
console.log(project)
console.log(project.project.user)
return project.project;
})
There's no need for you to create your own object when returning, since it's the same as project.project
.返回时无需创建自己的 object ,因为它与
project.project
相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.