【发布时间】:2021-07-30 10:55:01
【问题描述】:
我正在使用 bootstrap-table 并尝试显示一个包含来自 firebase 实时数据库的数据的表。
数据库的内容正确呈现,但是我也在我的表中看到“未找到匹配的记录”消息。
使用搜索和排序功能还可以完全清除表格,并且需要刷新才能恢复数据。
import React, { useState, useEffect } from "react";
import firebaseDb from "../firebase";
const StarTrekTable = () => {
var [contactObjects, setObjects] = useState({});
useEffect(() => {
firebaseDb.child("unwatched").on("value", (snapshot) => {
if (snapshot.val() != null)
setObjects({
...snapshot.val(),
});
});
}, []);
return (
<>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display -4 text-center">Star trek series</h1>
</div>
</div>
<div>
<div className="col-md-12">
<table data-toggle="table" data-pagination="true" data-search="true">
<thead className="thread-light">
<tr>
<th>Title</th>
<th>Series</th>
<th>Season</th>
<th>Episode</th>
<th>Stardate</th>
<th>Air Date</th>
</tr>
</thead>
<tbody>
{Object.keys(contactObjects).map((id) => {
return (
<tr>
<td>{contactObjects[id].title}</td>
<td>{contactObjects[id].series}</td>
<td>{contactObjects[id].season}</td>
<td>{contactObjects[id].episode}</td>
<td>{contactObjects[id].stardate}</td>
<td>{contactObjects[id].airdate}</td>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
</>
);
};
export default StarTrekTable;
非常感谢任何帮助。
Table shows both records as expected and "No matching records found"
【问题讨论】:
标签: reactjs firebase firebase-realtime-database bootstrap-4 bootstrap-table