我正在嘗試使用來自 firestore 集合的數據填充一個表。數據來得很完美,但是當我在控制臺記錄數據時,每一行的數據都以一種混亂的方式出現。讓我告訴你我想要什么以及它是如何到來的。假設我在集合中有 4 個文檔,ABC鍵為_name, _contact, _comments.預測輸出:{ { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, { _name: 'ABC', _contact: 'xyz', _comment: 'def' }}實際輸出來了:{ { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, { _contact: 'xyz', _name: 'ABC', _comment: 'def' }, { _name: 'ABC', _comment: 'def', _contact: 'xyz' }, { _name: 'ABC', _contact: 'xyz', _comment: 'def' }}JS代碼const tableObj = document.getElementById('quoteVal');dbref.get().then(snap => { snap.forEach(item => { data = item.data(); let ele = document.createElement('tr'); for(let key in data) { if(data.hasOwnProperty(key)) { ele.innerHTML += '<td>' + data[key] + '</td>'; } } tableObj.append(ele); });});請幫幫我。我不明白為什么會這樣,因為我是 firebase 的新手。
來自 firebase 的數據正在以混亂的方式出現?
守著星空守著你
2022-12-22 10:03:12