我需要在列表中显示的按钮上显示工具提示。在下面的图片中,您可以看到一组按钮(每次数据都来自数据库时,这些按钮都将被操纵。)
但是问题是,在下图中,您可以看到列表中的按钮仅在第一行中的按钮上显示工具提示,而将鼠标悬停在第二行的按钮上时,工具提示则不显示提示。
我想显示所有按钮的工具提示。谁能告诉我我做错了什么?我已将我的代码添加到图片下方。
{
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>
<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>
<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>
<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>
<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>
);
});
}
答案 0 :(得分:2)
这是因为当您映射到项目列表时,用于触发弹出窗口的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>
<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>
<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>
<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>
<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>
);
});
}