简体   繁体   English

在 antd 表中单击后如何禁用按钮?

[英]How to disable the button once clicked in antd table?

Getting the table values through props.通过道具获取表格值。 The claim update function is working fine, but the record still there.声明更新功能工作正常,但记录仍然存在。 once I refresh or select another tab only after that the claimed record will be removed.一旦我刷新或选择另一个选项卡,则声明的记录将被删除。

{
  title: 'Action',
  dataIndex: 'action',
  render: (text, record) =>
          <Button class="claimBom-btn" onClick={(e) => this.handleClaim(e,text, record)} ><Icon type="plus-circle" />Claim</Button>
      }

This the button call for all record in the table此按钮调用表中的所有记录

在此处输入图片说明

Just pass along the button state in the datasource.只需传递数据源中的按钮状态。 When it is clicked mutate the datasource.当它被点击时改变数据源。

const [datasource, setDatasource] = useState([
{
 disabled: false,
 // others properties
}
]);


// On button click find the data and change disabled property
const onClick = (id) => {
 const source = datasource.find(source => source.id === id);
 source.disabled = true;
 setDatasource(datasource);
}

{
  title: 'Action',
  dataIndex: 'action',
  render: (text, record) =>
   <Button disabled={text.disabled} class="claimBom-btn" onClick={(e) => this.handleClaim(e,text, record)} ><Icon type="plus-circle" />Claim</Button>
}

You can simply pass the disabled prop to the button accordingly.您可以简单地将disabled道具相应地传递给按钮。 When calling this.handleClaim , set a state of which button should be disabled while handling, and pass that as a disabled prop to the button.调用this.handleClaim ,设置处理时应禁用哪个按钮的状态,并将其作为禁用this.handleClaim传递给按钮。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM