我想通过选定的ID来获取单个文档的数据。我曾尝试使用 "child "和 "orderByChild "函数,但在Web SDK 9中似乎不起作用。 以下是我在数据库表中的代码:
<Link to={`/view/${id}`}>
{id.data.dateCreate}
</Link>
以及 "视图 "页面中的代码:
const [user, setUser] = useState({});
const { id } = useParams();
useEffect(() => {
db
.orderByChild(`reports/${id}`)
.get()
.then((snapshot) => {
if (snapshot.exists()) {
setUser({ ...snapshot.val() });
} else {
setUser({});
}
});
}, [id]);
非常感谢您的帮助!