我正在寻找一种在firestore文档中迭代的正确方法;
this.globalCounters = firebase.firestore().collection('AnswersCounters').doc('Questions')
我找到了一种方法来使用Object.keys(),但我不认为这种方式是正确的。
this.unsubscribe_globalCounters = this.globalCounters.onSnapshot(this.showAnswers)
showAnswers(querySnapshot){
let snapshotData = querySnapshot.data();
let answersCounters =[]
Object.keys(snapshotData).map((i)=>{
answersCounters.push({key:i,count:snapshotData[i]})
})
}