【发布时间】:2020-08-05 06:59:48
【问题描述】:
我正在尝试使用来自 firestore 集合的数据填充表。数据来得很完美,但是当我在控制台记录数据时,每一行的数据都以打乱的方式出现。让我告诉你我想要什么以及它是如何实现的。
假设我在集合 ABC 中有 4 个文档,键为 _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 新手。
【问题讨论】:
标签: javascript jquery firebase google-cloud-firestore nosql