【问题标题】:Firestore/Javascript: Uncaught (in promise) TypeError: Failed to execute 'appendChild' on 'Node': 1 argument required, but only 0 presentFirestore/Javascript:未捕获(承诺中)类型错误:无法在“节点”上执行“appendChild”:需要 1 个参数,但只有 0 个存在
【发布时间】: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


    【解决方案1】:

    对不起,我已经想通了!我忘了将li 传递给patientNames.appendChild(); 如果还有人遇到同样的问题,那就是答案!

    patientNames.appendChild(li); 应该是预期的参数!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-03
      • 2016-12-11
      • 2015-01-20
      相关资源
      最近更新 更多