Javascript 来自firebase的数据是以随机方式来的吗?

Javascript 来自firebase的数据是以随机方式来的吗?,javascript,jquery,firebase,google-cloud-firestore,nosql,Javascript,Jquery,Firebase,Google Cloud Firestore,Nosql,我试图用来自firestore集合的数据填充一个表。数据是完美的,但当我在控制台上记录时,每一行的数据都是以无序的方式出现的。让我告诉你我想要什么,它是如何来的 假设我在集合中有4个文档ABC,其键为\u name、\u contact、\u comments 预测产量: { { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, { _name: 'ABC', _contact: 'xyz', _comment: 'def' }, {

我试图用来自firestore集合的数据填充一个表。数据是完美的,但当我在控制台上记录时,每一行的数据都是以无序的方式出现的。让我告诉你我想要什么,它是如何来的

假设我在集合中有4个文档
ABC
,其键为
\u name、\u contact、\u 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' }
}
实际输出即将到来:

{
  { _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);
    });
});
consttableobj=document.getElementById('quoteVal');
dbref.get().then(snap=>{
snap.forEach(项=>{
data=item.data();
设ele=document.createElement('tr');
for(让我们输入数据){
if(data.hasOwnProperty(key)){
ele.innerHTML+=''+数据[键]+'';
}
}
表对象附加(ele);
});
});

请帮帮我。我不明白为什么会发生这种情况,因为我是firebase的新手。

您的代码不应该依赖于文档中字段的迭代顺序没有保证订购


如果您需要订单,您应该在生成输出之前自己对字段进行排序。

您的代码不应该依赖于文档中字段的迭代顺序没有保证订购

如果需要订单,则应在生成输出之前自行对字段进行排序