twitter-bootstrap - Bootstrap 折叠表动画不起作用
问题描述
我是一个正在学习的初学者。我想做一个简单的项目,我在其中使用引导程序来制作一个可扩展的表格,但是当我单击可折叠的 td 时,它只是展开和关闭而没有任何效果。我想了解发生了什么冲突。
import React, { Fragment } from 'react';
import { Link } from 'react-router-dom';
import '../../node_modules/bootstrap/dist/css/bootstrap.min.css';
import "../../node_modules/bootstrap/js/src/collapse.js";
const UserList = (props) => {
return (
<div >
<table className="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Mail</th>
<th colSpan="3" scope="col">Contacts</th>
</tr>
</thead>
<tbody>
{props.users.map((user, i) => (
<Fragment>
<tr key={i} data-toggle="collapse"
data-target={".multi-collapse" + i}
aria-controls={"multiCollapseExample" + i} >
<th scope="row">{user.id}</th>
<td>{user.name}</td>
<td>{user.mail}</td>
<td>{user.contact}</td>
<td><Link type="button"
to={`edit/${user.id}`}
className="btn btn-md btn-outline-primary"
>Edit</Link></td>
<td><button className="btn btn-md btn-outline-danger" data-target={i} onClick={(event) => props.deleteUserProp(user)}>Delete</button></td>
</tr>
<tr className={"collapse multi-collapse" + i} id={"multiCollapseExample" + i} >
<td colSpan="6" className="collapsible clearfix" >
<div className="coldiv" > <h4> Address:</h4><p>{user.body}</p></div>
</td>
</tr>
</Fragment>
))}
</tbody>
</table>
</div>
)
}
export default UserList;
解决方案
您遇到的问题是引导程序中的动画不能在非块级元素上运行,例如<td>
or <tr>
。它将显示和隐藏它,但动画不会运行,因为动画的工作方式取决于元素是display: block
. 因此,您可以将内容包装在<td>
a 内的元素内<div>
,然后将collapse
类添加到该<div>
.
<tr>
<td>
<div id="element-id-to-identify-on-collapse-control" class="collapse">
<p>This element would be hidden and the animation will run</p>
</div>
<td>
<tr>
推荐阅读
- swift - 使用 Combine 观察泛型值
- firebase - Flutter 依赖冲突将 firebase-admin 添加到我的 pubspec.yaml
- python - 如何在python中更改单选按钮状态?
- laravel-7 - Composer 需要 maatwebsite/excel 未安装
- r - 努力在函数内循环
- java - Spring框架和Jersey集成
- python - 有没有办法在 MobileNetV2 上实现我自己的功能作为预处理?
- python - 如何使用 Python boto3 获取 s3 存储桶中超过 60 天的文件/对象的计数?
- google-app-engine - 如何在没有`dev_appserver.py`的情况下在 2021 年本地运行 App Engine 标准应用程序(用于开发/测试)?
- java - JNI-Callback 中的“CallObjectMethod”返回 NULL