工具提示在列表中无法正常工作

Tooltip is not working inside the List properly

我需要在列表中的按钮上显示工具提示。在下图中,您可以看到一组按钮(每次从数据库中获取数据时都会对其进行操作)。

但问题是,在下图中,您可以看到列表中的按钮仅在第一行的按钮上显示工具提示,而将鼠标悬停在第二行的按钮上时,工具提示不显示提示。

我想显示所有按钮的工具提示。谁能告诉我我做错了什么?我已经在图片下方添加了我的代码。

{
  Object.keys(chitties).map((key, index) => {
    return (
      <tr key={key}>
        <td>{index + 1}</td>
        <td>{chitties[key].chittyName}</td>
        <td>{moment(chitties[key].startDate).format("DD-MM-YYYY")}</td>
        <td>{chitties[key].psoId}</td>
        <td>{chitties[key].auctionDay}</td>
        <td>{chitties[key].totalMonth}</td>
        <td>{numberFormat(chitties[key].totalAmount)}</td>
        <td>
          <Link
            to={`/chitties/list/${this.props.match.params.id}/detail/${key}`}
          >
            <Button
              color="primary"
              className="btn-pill"
              id="UncontrolledTooltipExample"
            >
              <i className="fa fa-eye" />
            </Button>
            <UncontrolledTooltip
              placement="top"
              target="UncontrolledTooltipExample"
            >
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/list/${this.props.match.params.id}/edit/${key}`}>
            <Button
              color="secondry"
              className="btn-pill"
              id="UncontrolledTooltip"
            >
              <i className="fa fa-pencil" />
            </Button>
            <UncontrolledTooltip placement="top" target="UncontrolledTooltip">
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/${key}/addUser`}>
            <Button
              color="success"
              className="btn-pill"
              id="UncontrolledToolti"
            >
              <i className="fa fa-user-plus" />
            </Button>
            <UncontrolledTooltip placement="top" target="UncontrolledToolti">
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/${this.props.match.params.id}/auction/${key}`}>
            <Button color="danger" className="btn-pill" id="UncontrolledTool">
              <i className="fa fa-calendar-plus-o" />
            </Button>
            <UncontrolledTooltip placement="top" target="UncontrolledTool">
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link
            to={`/chitties/${this.props.match.params.id}/paymentList/${key}`}
          >
            <Button color="warning" className="btn-pill" id="Uncontrolle">
              <i className="fa fa-inr" />
            </Button>
            <UncontrolledTooltip placement="down" target="Uncontrolle">
              Hello world!
            </UncontrolledTooltip>
          </Link>
        </td>
      </tr>
    );
  });
}

这是因为当您映射到项目列表时,用于触发弹出窗口的 ID 不是唯一的。

您可以通过将您正在使用的 key 添加到提到的 ID 来解决此问题:

<Button
  color="primary"
  className="btn-pill"
  id={`tooltip1-${key}`}
>
 <i className="fa fa-eye" />
</Button>
<UncontrolledTooltip
  placement="top"
  target={`tooltip1-${key}`}
 >

完整代码:

{
  Object.keys(chitties).map((key, index) => {
    return (
      <tr key={key}>
        <td>{index + 1}</td>
        <td>{chitties[key].chittyName}</td>
        <td>{moment(chitties[key].startDate).format("DD-MM-YYYY")}</td>
        <td>{chitties[key].psoId}</td>
        <td>{chitties[key].auctionDay}</td>
        <td>{chitties[key].totalMonth}</td>
        <td>{numberFormat(chitties[key].totalAmount)}</td>
        <td>
          <Link
            to={`/chitties/list/${this.props.match.params.id}/detail/${key}`}
          >
            <Button
              color="primary"
              className="btn-pill"
              id={`tooltip1-${key}`}
            >
              <i className="fa fa-eye" />
            </Button>
            <UncontrolledTooltip
              placement="top"
              target={`tooltip1-${key}`}
            >
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/list/${this.props.match.params.id}/edit/${key}`}>
            <Button
              color="secondry"
              className="btn-pill"
              id={`tooltip2-${key}`}
            >
              <i className="fa fa-pencil" />
            </Button>
            <UncontrolledTooltip placement="top" target={`tooltip2-${key}`}>
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/${key}/addUser`}>
            <Button
              color="success"
              className="btn-pill"
              id={`tooltip3-${key}`}
            >
              <i className="fa fa-user-plus" />
            </Button>
            <UncontrolledTooltip placement="top" target={`tooltip3-${key}`}>
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link to={`/chitties/${this.props.match.params.id}/auction/${key}`}>
            <Button color="danger" className="btn-pill" id={`tooltip4-${key}`}>
              <i className="fa fa-calendar-plus-o" />
            </Button>
            <UncontrolledTooltip placement="top" target={`tooltip4-${key}`}>
              Hello world!
            </UncontrolledTooltip>
          </Link>
          &nbsp;&nbsp;
          <Link
            to={`/chitties/${this.props.match.params.id}/paymentList/${key}`}
          >
            <Button color="warning" className="btn-pill" id="Uncontrolle">
              <i className="fa fa-inr" />
            </Button>
            <UncontrolledTooltip placement="down" target="Uncontrolle">
              Hello world!
            </UncontrolledTooltip>
          </Link>
        </td>
      </tr>
    );
  });
}