0

我有一个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调用。

我该如何解决这个问题?

4

1 回答 1

1

您可以使用stopPropagation(). 因此,在删除按钮的事件处理程序中,您必须像这样添加它:

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

    // handle click
}
于 2018-03-22T18:29:06.460 回答