2 回答

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊
您keyField應(yīng)該設(shè)置為dataField(鍵)而不是timestamps(值)。此外,不需要數(shù)據(jù)映射。
https://react-bootstrap-table.github.io/react-bootstrap-table2/docs/table-props.html#keyfield-required-string
IE
<BootstrapTable
keyField="dataField"
data={this.state.timestamps}
columns={columns}
pagination={paginationFactory()}
/>

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個(gè)贊
您正在傳遞整數(shù)數(shù)組而不是具有“時(shí)間戳”屬性的對(duì)象數(shù)組。
export const columns = [
{
dataField: "timestamp",
text: "Timestamp",
},
];
class Table extends Component {
constructor(props) {
super(props);
this.state = { timestamps: [] };
}
componentDidMount() {
const database = db.ref().child("timestamped_measures");
database.on("value", (ts_measures) => {
const timestamps = [];
ts_measures.forEach((ts_measure) => {
timestamps.push({ timestamp: ts_measure.val().timestamp });
});
console.log(timestamps);
this.setState((prevState) => {
return { timestamps: [...prevState.timestamps, ...timestamps] };
});
});
}
render() {
return (
<div className="App">
<BootstrapTable
keyField="timestamp"
data={this.state.timestamps}
columns={columns}
pagination={paginationFactory()}
/>
</div>
);
}
}
export default Table;
添加回答
舉報(bào)