简体   繁体   English

如何使用表格形式的GET API获取数据

[英]How Can i Get data using GET API In Tabular Form

I want to Display My Complaints Data in the Tabular Form Using the table. 我想使用表格以表格形式显示我的投诉数据。 i have tried using List it worked. 我试过使用列表它的工作。 I don't how to Display data in tabular form using Table. 我没有如何使用表格以表格形式显示数据。 When i have tried console log and postman it displays the data contained in the database. 当我尝试过控制台日志和邮递员时,它将显示数据库中包含的数据。 I want to get the data in the tabular form. 我想以表格形式获取数据。 Please help me with a solution. 请帮我解决。

 import React,{Component} from 'react'; import {Table} from 'react-bootstrap'; import axios from 'axios'; export default class Display extends React.Component{ constructor(props) { super(props); this.componentDidMount(); this.state = { complaints: [] }; } componentDidMount() { axios.get(`http://localhost:80/get/complaints`) .then(res => { // console.log(res.data) // const complaints = res; this.setState({ complaints: res.data }); }) } render() { console.log(this.state.complaints) return ( // <ul> // {this.state.complaints.map(complaints => ( // <li key={complaints.id}>{complaints.Regdno}</li> // ))} // </ul> <Table responsive> <thead> <tr > <th>Regd_no</th> <th>Year Of Study</th> <th>Location</th> <th>Department</th> <th> Disciplinary Issue</th> </tr> </thead> </Table> ) } } 

Displaying data in Tabular form from an API response can be done using fixed data table-2. 可以使用固定数据表2通过API响应以表格形式显示数据。 It provides a dynamic table with the number of rows as the index of your JSON object. 它提供了一个动态表,其中行数作为JSON对象的索引。

For more information , you may visit : http://schrodinger.github.io/fixed-data-table-2/example-object-data.html 有关更多信息,您可以访问: http : //schrodinger.github.io/fixed-data-table-2/example-object-data.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM