如何 return 对象 jsx 中的变量
how to return a variable in an object jsx
查看带有 >>> 的问题行。
目前的代码是这样的:
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;
}
您可以像这样使用变量作为对象键:
[menteeName]: firstEvent.modalData.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];
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;
}
您可以像这样使用变量作为对象键:
[menteeName]: firstEvent.modalData.menteeName