0

用>>>查看有问题的行。代码目前是这样的:

tableData() {
    const filteredEvents = this.props.graphData.events.filter((event) =>
      moment(event.eventDate).isBetween(this.startMoment, this.endMoment)
    );

    const eventsByM = _.groupBy(filteredEvents, (event) => event.metadata.mId);
    const tableRows = Object.values(eventsByM).map((events) => {
      const firstEvent = events[0];

      return ({
>>>     "Mentee Name": firstEvent.modalData.menteeName,
        "Mentor Name": firstEvent.modalData.mentorName,
        "Conversations Logged": events.length,
        tableRowUrl: firstEvent.modalData.tableRowUrl,
      });
    });
    return tableRows;
  }

而且我想让字符串“Mentee Name”成为一个变量,但 jsx 并没有将它作为变量读取。我怎样才能做到这一点?我像这样尝试过,但它的字面意思是“menteeName”:

tableData() {
    const filteredEvents = this.props.graphData.events.filter((event) =>
      moment(event.eventDate).isBetween(this.startMoment, this.endMoment)
    );

    const eventsByM = _.groupBy(filteredEvents, (event) => event.metadata.mId);
    const tableRows = Object.values(eventsByM).map((events) => {
      const firstEvent = events[0];
      const menteeName = "Apprentice name";

      return ({
 >>>    menteeName: firstEvent.modalData.menteeName,
        "Mentor Name": firstEvent.modalData.mentorName,
        "Conversations Logged": events.length,
        tableRowUrl: firstEvent.modalData.tableRowUrl,
      });
    });
    return tableRows;
  }
4

1 回答 1

0

您可以使用变量作为对象键,如下所示:

[menteeName]: firstEvent.modalData.menteeName
于 2021-07-22T03:47:20.580 回答