Javascript 反应如何从event.currentTarget获取道具
react是否有从列表项获取this.props.values的干净方法 我基本上希望获得当前项目的道具,这样我就可以用数据填充一个模态对话框。根据下面的函数,我指定的自定义道具(如“id”)是可访问的,但我真的希望这样做并拥有所有道具Javascript 反应如何从event.currentTarget获取道具,javascript,reactjs,react-jsx,Javascript,Reactjs,React Jsx,react是否有从列表项获取this.props.values的干净方法 我基本上希望获得当前项目的道具,这样我就可以用数据填充一个模态对话框。根据下面的函数,我指定的自定义道具(如“id”)是可访问的,但我真的希望这样做并拥有所有道具 event.currentTarget.this.props.note 处理程序 clicker(event){ console.log('clicking the clicker'); console.log(event.currentT
event.currentTarget.this.props.note
处理程序
clicker(event){
console.log('clicking the clicker');
console.log(event.currentTarget.id);
this.setState({isEdit: true});
console.log(this.state.isEdit);
}
查看
<div id={this.props.id} onClick={this.clicker} className="aui-item page-card off-track notecards">
<div className="project-details">
<div className="card-container">
<div className="left">
<h6>Title</h6>
<span>{this.props.note.content}</span>
<h6 className="compact">Last status report</h6>
<span>{this.props.note.updatedAt}</span>
</div>
<div className="right">
<span>something</span>
</div>
</div>
</div>
</div>
标题
{this.props.note.content}
最后状态报告
{this.props.note.updatedAt}
某物
您可以直接访问clicker内的道具
clicker(event){
console.log('clicking the clicker');
console.log(this.props.id);
this.setState({isEdit: true});
console.log(this.state.isEdit);
}
在这种情况下,最好创建单独的组件。在我看来,没有必要创建大视图 因此,您的组件应该如下所示:
功能项({
身份证件
更新日期:,
内容,,
onClick,
}) {
//我们应该将'id'变量传递给'onClick'处理程序。
返回(
onClick(id)}className=“aui项目页面卡偏离轨道记事卡”>
标题
{content}
最后状态报告
{updatedAt}
某物
);
}
或者,如果不想使用单独的组件,可以从clicker事件处理程序访问this.props
变量:
点击器(事件){
//这里可以使用这个道具。
this.setState({isEdit:true});
}