【发布时间】:2020-11-01 21:52:29
【问题描述】:
这是我的代码的 sn-p。它会生成一个表格,其中包含向每个人发送电子邮件邀请的选项。
constructor(props){
super(props)
this.state={
persons:[],
inviteSent: false,
}
}
async componentDidMount(){
this.setState({
patients:this.props.patients,
})
}
sendInvite = async (person) => {
let response = ***code to send email invite***
if(response.ok){
this.setState({
inviteSent: true,
})
}
}
let personList = this.props.personList
let persons = personList.map((person, index)=>
{
return (
<tr key={index}>
<td>
{!this.state.inviteSent &&
<div onClick={()=>this.sendInvite(person)}>Send Invite</div>
}
{this.state.inviteSent &&
<div>Email Sent</div>
}
</td>
</tr>
)
}
基本上,有一个按钮可以向表格中的每个人发送电子邮件邀请,一旦发送,该特定按钮应该会消失,并由“电子邮件已发送”的确认信息取代。但是,由于inviteSent 的状态没有映射到特定的人,它会使用“邀请已发送”更新所有行。我如何将它映射到那个特定的人?
【问题讨论】:
-
我看不到任何简单的解决方案,除了每个人都有一个名为“inviteSent”的新属性
标签: javascript reactjs mapping state