按下单元格内的按钮时处理单击事件

时间:2018-03-22 18:24:09

标签: reactjs primereact

我有DataTable这样:

render() {
    return(
      <div>
        <DataTable value={this.props.members} header="Members"
          selectionMode="single" onSelectionChange={this.onMemberSelected} 
        >
          <Column field='name' header='Name' sortable />
          <Column field='lastName' header='Last Name' sortable />
          <Column field='address' header='Address' sortable />
          <Column field='country' header='Country' sortable />
          <Column body={ (member, _) => {
            return this.renderDeleteButton(member);
          } }/>
        </DataTable>
      </div>
    );
}

renderDeleteButton(member) {
    return (
        <Button
            label="Delete"
            onClick={ e => { 
                //delete member
            }}
        />
    );
}

onMemberSelected(e) {
    //show member detail
}

当我按“删除”按钮时,它会显示成员详细信息,因为该行正在处理该事件并且调用了onMemberSelected

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您可以使用stopPropagation()停止对合成事件的传播。因此,在删除按钮的事件处理程序中,您必须像这样添加它:

handleDeleteButtonClick = event => {
    event.stopPropagation();

    // handle click
}