Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
Error: no capturado (en promesa) TypeError: doc no es una función en HTMLButtonElement. <anónimo>

Por lo tanto, he intentado seguir el tutorial de The Net Ninja para mi sitio web. Aquí está el enlace del tutorial que he seguido. Pero tengo que cambiar algunos códigos ya que su versión de firebase es antigua.

Lo que estoy tratando de hacer es eliminar la fila pero salió este error:

 Uncaught (in promise) TypeError: doc is not a function at HTMLButtonElement.<anonymous>

Esta es la codificación javascript:

 function renderList(doc){ let trow = document.createElement('tr'); let td1 = document.createElement('td'); let td2 = document.createElement('td'); let ControlDiv = document.createElement("div"); const date = doc.data().created.toDate().toDateString(); trow.setAttribute('data-id', doc.id); td1.textContent = doc.data().email; td2.textContent = date; ControlDiv.innerHTML = '<button id="DelModBtn" type="button" class="btn btn-danger btn-primary my-2 ml-2">Delete</button>' trow.appendChild(td1); trow.appendChild(td2); trow.appendChild(ControlDiv); adminList.appendChild(trow); //deleting the data const deleteBtn = document.querySelector('#DelModBtn'); deleteBtn.addEventListener('click', async (e) => { e.stopPropagation(); let id = e.target.parentElement.getAttribute('data-id'); await deleteDoc(doc(firestore, "admin", id)); }) }

¿Alguien puede decirme qué está mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Parece que "doc" es un objeto, por lo que no puede llamarlo como una función.

Aquí hay un ejemplo de llamada de método de función y objeto:

 function sayHelloTo(name) { console.log('Hello to ' + name); } let helloTo = { getMessage: function(params) { return "Hello to "; }, chris: function(params) { console.log(this.getMessage() + 'chris'); }, bob: function(params) { console.log(this.getMessage() + 'bob'); }, bruh: function(params) { console.log(this.getMessage() + 'bruh'); }, } sayHelloTo('YOU'); // here I call a function such as is wrong in your code : "doc(firestore, "admin", id)" helloTo.chris(); // here I call object method such as "doc.data()" helloTo.bob(); helloTo.bruh();

Vi el video, el lanzador está usando un objeto llamado "db" y es posible que le devuelvan otro objeto después de llamar a "db.collection('cafes')" para explicarlo, podría ser algo como esto:

 // I've created some example classes to match with your turorial video let docClass = class Doc { // a class is a more complex object, that is used to create a lot of same object // constructor is a native method that is call at creation = "new docClass(0,'data')" // it will first execute code in "contructor" and then return "this", this is the current created object of the class constructor(id,indata){ this.id = id; this.indata = indata; } data(){ return this.indata; } delete(){ return 'i should delete something'; } } let collectionClass = class Collection { // it's a class too constructor(name){ this.name = name; this.docs = {}; } doc(id){ return this.docs[id]; } addDoc(doc){ this.docs[doc.id] = doc; } }; let dbClass = class DB { // it's a class too constructor(name){ this.collections = []; } collection(collectionName) { let index = this.collections.map(col=>col = col.name).indexOf(collectionName); return this.collections[index]; } addCollection(col){ this.collections.push(col); } } // so here we create object from classes let db = new dbClass('mydatabase'); let collection = new collectionClass('mycollection'); let docs_examples = [ new docClass(0,'data0'), new docClass(1,'data1'), new docClass(2,'data2'), new docClass(3,'data3'), ]; // here we call addDoc method to add Docs in collection object for (const doc of docs_examples) { collection.addDoc(doc); } // and here we add collection to db object db.addCollection(collection); // here you can see some similar lines with your tutorial video, but now you can understand and read how it works console.log(db.collection('mycollection')); console.log(db.collection('mycollection').doc(2)); console.log(db.collection('mycollection').doc(2).delete()); console.log(db.collection('mycollection').doc(2).data());

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!