【发布时间】:2018-07-31 15:38:46
【问题描述】:
我正在使用 create-react-app 和 react-bootstrap 构建一个基本的 react 应用程序。我正在使用表格来显示来自 react-bootstrap https://react-bootstrap.github.io/components/table/ 的信息。我正在尝试让分页为表格工作,但我不确定如何绕过它来处理表格。以下是我的组件的代码 sn-p,我添加了 react-bootstrap 中的分页代码片段,它仅在底部显示分页页脚,但实际上并未对结果进行分页。 应用.js
import React, { Component } from 'react';
import Table from 'react-bootstrap/lib/Table';
import Pagination from 'react-bootstrap/lib/Pagination';
export class App extends Component {
renderList() {
return(
<Table striped hover bordered condensed>
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>Forks</th>
<th>Clone URL</th>
</tr>
</thead>
<tbody>
{this.state.response.map((object) => {
return (
<tr>
<td><a onClick={this.handleClick.bind(this,object)}>{object.name} </a></td>
<td>{object.description}</td>
<td><Glyphicon glyph="cutlery" /> {object.forks_count}</td>
<td>{object.clone_url}</td>
</tr>
);
})}
</tbody>
</Table>
);
}
renderPagination() {
let items = [];
for (let number = 1; number <= 10; number++) {
items.push(
<Pagination.Item>{number}</Pagination.Item>
);
}
return (
<Pagination bsSize="small">{items}</Pagination>
);
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<h1 className="App-title">Netflix Repositories</h1>
</header>
{this.renderList()}
<CommitList ref={(ref) => this.commitList = ref}
show={this.state.show}
commits={this.state.commits} />
{this.renderPagination()}
</div>
);
}
}
如何对表格上的结果进行分页?
【问题讨论】:
标签: reactjs react-bootstrap create-react-app