javascript - 从 react-bootsrap 崩溃不起作用
问题描述
我正在尝试使用来自 react-bootstrap的 Collapse 创建一个可折叠的表格行。
我想创建在单击时展开和折叠的表格行,以便我可以显示有关该特定行的更多信息。
在 react-bootstrap 页面上它似乎可以工作,但是当我复制它以使用 a 而不是 a 它停止工作。这是我的代码:
import React, { useState } from 'react';
import Collapse from 'react-bootstrap/Collapse';
import Table from "react-bootstrap/Table";
function OppTable (props) {
const [open, setOpen] = useState(false);
return (
<>
<Table
striped bordered hover
onClick={() => setOpen(!open)}
aria-controls="example-collapse-text"
aria-expanded={open}>
<thead>
<tr>
<th>Name</th>
<th>City</th>
<th>Last visited</th>
<th>Visits</th>
<th>FTE</th>
</tr>
</thead>
<tbody>
{
props.opportunities.map(opportunity => {
return (
<>
<tr onClick={() => setOpen(!open)} aria-controls="example-collapse-text" aria-expanded={open}>
<td>{opportunity.companyname}</td>
<td>{opportunity.city}</td>
<td>{opportunity.lastVisit}</td>
<td>{opportunity.totalVisits}</td>
<td>{opportunity.employees}</td>
</tr>
<Collapse>
<tr id="example-collapse-text">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</tr>
</Collapse>
</>
)
})
}
</tbody>
</Table>
</>
);
}
export default OppTable;
有谁知道我做错了什么?
解决方案
缺少表的导入语句,您正在使用表,但您没有从 react-bootstrap 导入表
从“react-bootstrap/Table”导入表;
import React, { useState } from 'react';
import Collapse from 'react-bootstrap/Collapse';
// import Button from "react-bootstrap/Button";
import Table from "react-bootstrap/Table";
function Example() {
const [open, setOpen] = useState(false);
return (
<div>
<Table
striped bordered hover
onClick={() => setOpen(!open)}
aria-controls="example-collapse-text"
aria-expanded={open}
>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Mark</td>
</tr>
<tr>
<td>2</td>
<td>Jacob</td>
</tr>
<tr>
<td>3</td>
<td colSpan="2">Larry the Bird</td>
</tr>
</tbody>
</Table>
<Collapse in={open}>
<div id="example-collapse-text">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus
terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer
labore wes anderson cred nesciunt sapiente ea proident.
</div>
</Collapse>
</div>
);
}
export default Example;
推荐阅读
- c# - 从第一个表单调用第二个表单实例。但是当回到第一个表单时,第二个表单实例不会关闭
- javascript - 量角器 - JavaScript - 有没有办法只在代码的某些部分中定位对象
- sql-server-2012 - 使用 CTE 的查询性能
- vbscript - 计算是递归的
- node.js - 从客户端终止 Google Speech-To-Text streamingRecoginze() RPC 调用(Node.js SDK)
- reactjs - 将函数结果传递给 graphql 突变
- azure-devops - MSBUILD.EXE 环境变量
- python - python - 如何限制每个循环读取多个带引号的字符串作为python中的单个字符串?
- grafana - Grafana - 从计数器数据创建表
- java - Java 多线程 - 主线程已停止