【发布时间】:2020-01-31 12:04:42
【问题描述】:
我目前正在关注tutorial 并完全遵循它,但将其调整为我的编码风格。
我想要在我的网页上显示名为patients 的firestore 子集合中uid 的某些字段。但我不断收到错误
Uncaught (in promise) TypeError: Failed to execute 'appendChild' on “节点”:需要 1 个参数,但只有 0 个存在
这与教程中显示的预期输出完全矛盾。
这是我的代码:
<div class="card">
<div class="card-body text-center">
<div class="card-body text-left">
<script>
firebase.auth().onAuthStateChanged(user => {
if(user){
this.userId = user.uid;
} //stores the user id in variable
const patientNames = document.querySelector('#patientList');
function renderPatientList(doc){
//var
let li = document.createElement('li');
let firstName = document.createElement('span');
let lastName = document.createElement('span');
let sex = document.createElement('span');
li.setAttribute('data-id', doc.id);
firstName.textContent = doc.data().firstName;
lastName.textContent = doc.data().lastName;
sex.textContent = doc.data().sex;
li.appendChild(firstName);
li.appendChild(lastName);
li.appendChild(sex);
patientNames.appendChild();
}
console.log(userId);
let userRef1 = firebase.firestore().collection("users").doc(userId).collection("patients");
return userRef1.get()
.then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
// doc.data() is never undefined for query doc snapshots
console.log(doc.id, " => ", doc.data());
renderPatientList(doc);
});
});
});
</script>
<div>
<ul class id="patientList"></ul>
</div>
</div>
</div>
这是作为错误返回给我的代码patientNames.appendChild();
【问题讨论】:
标签: javascript html firebase google-cloud-firestore