【发布时间】:2021-01-11 20:13:49
【问题描述】:
我正在开发一个网站,它的底部有一个评论部分。我开发了一个“添加评论”按钮,将评论存储到 firebase firestore。但是,我正在努力解决如何在我的网站上显示 cmets。我知道如何从 firestore 获取所有 cmets,但我不知道如何在我的网站上显示它们。我在谷歌上搜索了几个小时,但没有完全找到我想要的,因此感谢您的帮助。
所以,我有一个评论输入和一个提交按钮:
<input
type="text"
class="form-control"
placeholder="Comment"
id="comment"
aria-describedby="basic-addon1"
/>
<button
type="button"
class="btn btn-dark"
data-bs-dismiss="modal"
onclick="postComment()"
>
Comment
</button>
还有一个将其发布到 firebase firestore 的功能:
function postComment() {
var name = document.getElementById("name").value;
var comment = document.getElementById("comment").value;
let db = firebase.firestore();
db.collection("comments")
.add({
name,
comment,
time: firebase.firestore.Timestamp.fromDate(new Date()),
})
.catch((error) => {
console.log(error);
});
}
这就是我从 firestore 获取数据的方式:
db.collection("cities").get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
});
现在我只想知道一种在我的网站上显示 cmets 的动态方式。换句话说,评论部分的布局/模型。
提前致谢
【问题讨论】:
-
你能得到数据吗?问题只是向他们展示?或者如何消费和展示?
标签: javascript html css firebase