function snapshotToArray(snapshot) {
var returnArr = [];
snapshot.forEach(function(childSnapshot) {
var item = childSnapshot.val();
item.key = childSnapshot.key;
returnArr.push(item);
});
return returnArr;
};
firebase.database().ref('books').on('value', function(snapshot) {
const list_div = document.querySelector("#list");
list_div.innerHTML += "<div class='list-item'><h3></h3>" + snapshot.val() + "</div>"
console.log(snapshotToArray(snapshot));
});
<div class="main-list" id="list">
<div class="list-item">
<h3>Kitaplarım:</h3>
</div>
</div>
我已经尝试解决了3天
答案 0 :(得分:1)
HTML无法理解js对象,因此您必须将所有值作为字符串传递,在当前情况下snapshot.val()
是一个对象,要解决此问题,您可以将snapshot.val()
替换为{{1 }}