Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
73 views
in Technique[技术] by (71.8m points)

Delete data from firebase using html on javascript

I have a function to render cards with information from my firebase DB.

The div that i'm using at javascript file:

                    <div class="col-md-4">
                      <div class="card mb-4 box-shadow">
                        <img class="card-img-top" data-src="${doc.data().foto}">
                        <div class="card-body">
                          <p class="card-text">Local: ${doc.data().local}</p>
                          <p class="card-text">Descricao: ${doc.data().descricao}</p>
                          <p class="card-text">Situacao: ${doc.data().situacao}</p>
                          <div class="d-flex justify-content-between align-items-center">
                            <div class="btn-group">
                              <button type="button" class="btn btn-sm btn-outline-secondary" data-toggle="modal" data-target="#myModal">Edit</button>
                              <button type="button" class="btn btn-sm btn-outline-secondary type="submit" onclick="deleteCard(${doc.id})">Apagar</button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>

As you can see I need to create a button to delete this information.

I'm trying to pass to the function

function deleteCard(id) {


    db.collection("ocorrencias").doc(id).delete().then(function() {
        console.log("Document successfully deleted!");
    }).catch(function(error) {
        console.error("Error removing document: ", error);
    });

}


The console tho is sending the me the error:


Uncaught ReferenceError: IcKDt_____pUQcy is not defined
    at HTMLButtonElement.onclick (myindexLogged.html:1)

What i'm doing wrong ??

question from:https://stackoverflow.com/questions/66055005/delete-data-from-firebase-using-html-on-javascript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Perhaps replace deleteCard(${doc.id}) with deleteCard(${doc.data().id})


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...