首页 > 解决方案 > RN Javascript - 修改对象列表中的条目

问题描述

有一个逻辑问题让我整天发疯;希望你们能帮忙!

因此,我使用 google maps api 从日历中返回事件列表,然后过滤这些事件以查找用户所属的特定事件(电子邮件在与会者中);现在我正在尝试提取活动参与者,检查其他用户的电子邮件,对其运行查询以返回他们的姓名和图片,然后将该对象及其姓名和图片附加到原始活动中,然后再次返回整个列表与更新的条目。

这是我从服务器获得的事件:

{ ...
  id: 'ID',
  status: 'confirmed',
  description: 'Keyword' 
  start: [Object],
  end: [Object],
  attendees: [Array],
  reminders: [Object]
  ...
}

我提取不是用户的与会者的电子邮件,并在我的本地数据库上运行查询以获取他们的姓名和照片,然后我想添加,以便事件显示为这样;

{ ...
  id: 'ID',
  status: 'confirmed',
  description: 'Keyword' 
  start: [Object],
  end: [Object],
  attendees: [Array],
  reminders: [Object]
  ...
  opponent: {name: 'Name', picture: 'Picture_URL'}
}

这是我到目前为止所拥有的:

const events = results.data.items.filter(event => {
    return (
      event.description &&
      event.description.includes('Keyword') &&
      event.attendees.some(attendee => {
        return attendee.email === currentUser.email;
      })
    );
  });

Events come back fine from here, filtered with the events that include the user in attendees. I can't seem to get the next bit to work where I would modify the {event} object and add the {opponent} to it.

  const opponent = events.map(event => {
    return event.attendees.filter(async attendee => {
      if (attendee.email !== currentUser.email) {
        return await prisma.query
          .user({ where: { email: attendee.email } })
          .then(user => {
            return {
              name: user.name,
              picture: user.picture,
            };
          })
          .catch(err => {
            return;
          });
      }
    });
  });

PS:prisma.query.user 返回一个 Promise。

非常感谢任何关于我所缺少的方向或帮助!

多谢你们!:)

标签: javascriptarraysreact-nativeobjectlogic

解决方案


推荐阅读