简体   繁体   English

如何禁用重复列表上的单击按钮

[英]How to disable the clicked button on a repeat list

I have a code that disables a button when clicking on it, this works, but it's disabling all the buttons I have on the screen.我有一个代码,当点击它时禁用一个按钮,这是有效的,但它禁用了我在屏幕上的所有按钮。

This is the part of code:这是代码的一部分:

  constructor(props) {
    super(props);
    autoBind(this);
    this.state = { isLoading: false };
  }
  
  
  handleFile(file) {
    const id = file.id; // Maybe I can use this id

    this.setState({ isLoading: true });
    if (document.statusCode == 200) {
      this.setState({ isLoading: false });
    } 
  }


  _renderButton(text, props) {
    const isFile = (props.type.toLowerCase() === 'file');
    return (
      <Row>
        {isFile && (
          <Button disabled={this.state.isLoading} onClick={(e) => { e.stopPropagation(); this.handleFile(props)}} />
        )}
        {props.deleted ? // some code : // another code }
      </Row>
    );
  }

How can I disable just the clicked button using react?如何使用反应仅禁用单击的按钮?

Thank you in advance who can help me with this.预先感谢您可以帮助我解决这个问题。

If you have three buttons you can toggle them individually like this.如果您有三个按钮,您可以像这样单独切换它们。

constructor(props) {
    super(props);
    autoBind(this);
    this.state = { isLoading: [false,false,false] };
  }
  
  
  handleFile(file,index) {
    const id = file.id; // Maybe I can use this id

    this.setState({ isLoading: true });
    if (document.statusCode == 200) {
      const newLoading = this.state.isLoading;
      newLoading[index] = true;

      this.setState({ isLoading: newLoading });
    } 
  }


  _renderButton(text, props,index) {
    const isFile = (props.type.toLowerCase() === 'file');
    return (
      <Row>
        {isFile && (
          <Button disabled={this.state.isLoading[index]} onClick={(e) => { e.stopPropagation(); this.handleFile(props)}} />
        )}
        {props.deleted ? // some code : // another code }
      </Row>
    );
  }

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

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