因此,我正在尝试从Firestore检索数据并将其显示在我的网页上,我已经尝试了一切,并且穷尽了该站点上的每个问题,但无济于事。
当我使用下面的代码时,网站页面上不会呈现任何内容,但是,当我将带注释的代码与虚拟数据而不是Firestore查询检索数据一起使用时,该数据将按原样呈现。
我在虚拟数据和Firestore数据上都使用了console.log(),它们都记录了相同的数据数组。
我对为何即使正确保存数组后,firestore数据也无法显示匹配项感到困惑。
class MatchHistoryForm extends Component {
constructor(props) {
super(props);
var Matches = [];
firebase
.firestore()
.collection("Matches")
.orderBy("date")
.limit(10)
.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
Matches.push({
team1: doc.data().team1,
team2: doc.data().team2,
winner: doc.data().winner,
date: doc.data().date
});
});
})
.catch(function(error) {
console.log("Error getting documents: ", error);
});
// var Matches = [{
// team1: "asdf",
// team2: "jkl",
// winner: "team1",
// date: "1/2/2018",
// }, {
// team1: "qwer",
// team2: "yuio",
// winner: "team2",
// date: "1/8/2018",
// }]; …Run Code Online (Sandbox Code Playgroud)