我在React中有一个表,它的行不是html元素,所以我可以用通常的方式映射。它的数据通过道具。示例如下:
<Table
data={{head:{},data:[
{
data_creare:"20.01.2020",
detalii:"React example"
}
]}}
/>我想做一些像这样的事情
[this.state.message.map((list)=> {data_creare:list.a, detalii:list.b}]但它不起作用。我知道如何通过html元素进行映射,但不知道如何使用props。请举个例子吧。
这就是我得到这个表的地方,您可以找到文档:NPM package link
这是我的代码:
import React, { useState } from 'react';
import Table from 'react-responsive-data-table';
import axios from 'axios';
class ListaMesaje3 extends React.Component {
componentDidMount() {
axios.get(`http://11111111:111111/listamesaje`)
.then(res => {
const persons = res.data;
console.log(persons.mesaje);
this.setState({mesajex:persons.mesaje});
console.log(this.state.mesajex);
})
}
constructor(props) {
super(props);
this.state = {
titlu: 'Lista mesaje',
mesajex:[],
x:[]
}
}
render() {
return(
<div id="tot">
<h3>{this.state.titlu}</h3>
<Table style={{
opacity: 0.8,
backgroundColor: "#00113a",
color: "#ffffff",
textAlign: "center"}} tableStyle="table table-hover table-striped -striped-bordered-responsive“pages={true} pagination={true} onRowClick={() => {}} //如果需要表行数据行,则分配此{row => console.log( Row )} page={true} errormsg=”错误. .“Loadingmsg=“正在加载...”isLoading={false} sort={true} title="Lista mesaje“search={true} size={10} data={{ head:{ data_creare:”数据存储“,detalii:”数据存储“,
},
data:[
{
data_creare:"",
detalii:""
}
]
}} />
</div>
);
}
}
export default ListaMesaje3;提前感谢
发布于 2021-03-25 18:09:39
需要先提供表头作为表头,然后根据表头提供表体行作为对象。
<Table
data={
{
head:{
data_creare:"Data Created",
details:"Description"
},
data:[
{
data_creare:"20.01.2020",
details:"React example"
}
]
}
}/>https://stackoverflow.com/questions/66796785
复制相似问题